Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
A message Socket.controller
is a bidirectional stream of message
. The creator of a value of this type can:
message
is received,val make : receive:('a -> unit) -> 'a controller
make ~receive
creates a new controller that will call receive
when a message is received.
val set_receive : 'a controller -> ('a -> unit) -> unit
set_receive
sets the callback invoked when a message is received.
set_on_closed
sets the callback invoked when the connection terminates. Closing is definitive (it can happen at most once).
val set_on_closed : 'a controller -> (unit -> unit) -> unit
set_on_closed
sets the callback invoked when the connection terminates. Closing is definitive (it can happen at most once).
set_on_connected
sets the callback invoked when the connection is established. It can be invoked at most once.
val set_on_connected : 'a controller -> (unit -> unit) -> unit
set_on_connected
sets the callback invoked when the connection is established. It can be invoked at most once.
val send : 'msg controller -> 'msg -> unit
send ctrl msg
sends one message to the other end. status (endpoint ctrl)
should be `Connected
for this to succeed. Fail with Invalid_argument
otherwise.
val close : 'msg controller -> unit
close ctrl
terminates the connection now. If status (endpoint ctrl)
is `Pending
or `Connected
, it is updated to `Closed
and on_closed
callback is invoked. If status (endpoint ctrl)
is already `Closed
, nothing happens.
val endpoint : 'a controller -> 'a t
val status : 'msg t -> [ `Pending | `Connected | `Closed ]
Get the status of the socket. Possible statuses are:
`Pending
, connection has not been established yet, no message should be sent yet.`Connected
, connection has been established, messages can be sent.`Closed
, connection is terminated, no messages can be sent anymore.