Skip to content

Instantly share code, notes, and snippets.

@avsm
Created April 13, 2011 20:59
Show Gist options
  • Save avsm/918401 to your computer and use it in GitHub Desktop.
Save avsm/918401 to your computer and use it in GitHub Desktop.
Echo server
let echo () =
lwt mgr, mgr_t = Manager.create () in
let src = None, 8081 in
Flow.listen mgr (`TCPv4 (src,
(fun (addr, port) t ->
Console.log "From %s:%d" (ipv4_addr_to_string addr) port);
let rec echo () =
lwt res = Flow.read t in
match res with
|None ->
Console.log "Connection closed";
return ()
|Some data ->
Flow.write t data >>= echo
in
echo ()
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment