Download The demexp Book - Linux
Transcript
Function connect to server opens a new TCP connection to the server and logs in as the user defined in pref (of type Pref.preferences class). This function returns the client identifier and the login cookie. The function can raise a Connection error exception. 170 hdemexp-gtk2-client.ml 168ai+≡ / 169c 171 . let connect_to_server pref user_msg = let timer = Perf.timer_start () in user_msg (Printf.sprintf (f_ "Connecting to server %s:%d...") pref#server_name pref#server_port); try let client = Demexp.V1.create_client (Rpc_client.Inet (pref#server_name, pref#server_port)) Rpc.Tcp in let login = pref#user_login in let pass = pref#user_password in user_msg (Printf.sprintf (f_ "Connected to server. Try to login with \"%s\"...") login); let r = Demexp.V1.login client (Rtypes.int_of_uint4 protocol_version, login, pass) in if r.login_return_code <> rt_ok then ( MiscUI.display_error (Printf.sprintf (f_ "Unable to login (%s).\nContinue as Anonymous (just browse).") (Misc.string_of_return_code r.login_return_code)) ) else user_msg (s_ "Logged in."); if r.server_protocol_version <> Rtypes.int_of_uint4 protocol_version then ( MiscUI.display_error (Printf.sprintf (f_ "Unmatched protocol version (server:%d <> client:%d), please upgrade your demexp r.server_protocol_version (Rtypes.int_of_uint4 protocol_version)); raise Connection_error; ); Perf.timer_stop_and_record "Browser.connect_to_server" timer; (client, r.login_cookie) with | Unix.Unix_error (err, _, _) -> MiscUI.display_error (Printf.sprintf (f_ "Unable to connect to server: %s") (Glib.Convert.locale_to_utf8 (Unix.error_message err))); raise Connection_error | Failure str -> MiscUI.display_error (Printf.sprintf (f_ "Unable to connect to server: %s") (Glib.Convert.locale_to_utf8 str)); raise Connection_error | Rpc.Rpc_server err -> MiscUI.display_error (Printf.sprintf (f_ "RPC error returned by server (%s). You should probably upgrade your demexp clien (string_of_rpc_error err)); raise Connection_error 170