Module Netmsg

Send messages over stream sockets.

Connection

type t

The type for connections.

val connect : endpoint:Funix.endpoint -> (t option, string) Stdlib.result

connect ~endpoint connects to a server offered on endpoint endpoint. None is returned if no server could be found.

val close : t -> unit

close c closes a connection. This never errors.

val fd : t -> Unix.file_descr

fd c is the file descriptor of c.

Communication

val send : t -> string -> (bool, string) Stdlib.result

send c s sends bytes s on c. The result is Ok false if the peer ends the connection, no guarantees that the message went through.

val recv : t -> (string option, string) Stdlib.result

recv c receives bytes from c and is Ok None if the peer ends the connection.

Connection listeners

type listener

The type for connection listeners.

val listener : ?backlog:int -> endpoint:Funix.endpoint -> unit -> (listener, string) Stdlib.result

listener ~backlog ~endpoint () is a connection listener on endpoint. backlog is the argument for Unix.listen (defaults to 128).

val listen : listener -> (t, string) Stdlib.result

listen ~endpoint offers a connection on endpoint. Blocks until a client connects. The caller must eventually close the connection.

val close_listener : listener -> unit

close_listener l closes listener l.