Last active
February 27, 2016 15:44
-
-
Save Nnwww/35b65db5479441f84471 to your computer and use it in GitHub Desktop.
I picked up this snippet when netsurfing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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