Skip to content

Instantly share code, notes, and snippets.

@Nnwww
Last active February 27, 2016 15:44
Show Gist options
  • Save Nnwww/35b65db5479441f84471 to your computer and use it in GitHub Desktop.
Save Nnwww/35b65db5479441f84471 to your computer and use it in GitHub Desktop.
I picked up this snippet when netsurfing.
let () =
let sockaddr = Unix.ADDR_INET (Unix.inet_addr_of_string "0.0.0.0", 3333) in
let _server =
Lwt_io.establish_server sockaddr (fun (in_, out) ->
Lwt.catch (fun () ->
in_
|> Lwt_io.read_lines
|> Lwt_stream.iter_s (fun line -> Lwt_io.write_line out line)
) (fun _exn -> Lwt.return_unit (* callback shouldn't raise *))
|> Lwt.ignore_result
) in
let (t, _) = Lwt.wait () in
Lwt_main.run t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment