Up

Module Client

Signature

type t
val create' : ?logfun:< recv : To_client_msg.t; send : To_server_msg.t; remote_name : Server_name.t > logfun -> ?now:(unit -> Core.Std.Time.t) -> ?check_remote_name:bool -> ?credentials:string -> ip:string -> port:int -> expected_remote_name:Server_name.t -> Client_name.t -> t

create a new (initially disconnected) client

val create : ?logfun:< recv : To_client_msg.t; send : To_server_msg.t; remote_name : Server_name.t > logfun -> ?now:(unit -> Core.Std.Time.t) -> ?check_remote_name:bool -> ip:string -> port:int -> expected_remote_name:Server_name.t -> Client_name.t -> t

Just like create', but assume empty credentials (for backwards compatibility)

val connect : t -> unit Import.Deferred.t

connect t If the connection is not currently established, initiate one. Returns a deferred that becomes determined when the connection is established.

val close_connection : t -> unit

If a connection is currently established, close it. Also, if we're trying to connect, give up.

listen t

Returns a stream of messages from the server and errors
val listen_ignore_errors : ?stop:unit Import.Deferred.t -> t -> To_client_msg.t Import.Stream.t

listen_ignore_errors t like listen, but with no errors or meta data. When listen_ignore_errors is called it installs a filter on the stream that never goes away (unless t is destroyed or you provide a stop), so you should not call it many times throwing away the result. If you need to do this use listen.

val send : t -> To_server_msg.t -> [
| `Sent of Core.Std.Time.t
| `Dropped
] Import.Deferred.t

send t msg send a message to the server. If the connection is not currently established, initiate one.

Returns a deferred that is filled in with either the time the message was handed to the OS, or `Dropped. `Dropped means that there was an error, and the message will not be sent.
val send_ignore_errors : t -> To_server_msg.t -> unit

send_ignore_errors t exactly like send but with no error reporting.

val state : t -> [
| `Disconnected
| `Connected
| `Connecting
]

state t

Returns the state of the connection
val last_connect_error : t -> Core.Std.Error.t option

last_connect_error t returns the error (if any) that happened on the last connection attempt.

val flushed : t -> [
| `Flushed
]