Skip to content

Instantly share code, notes, and snippets.

@b0oh b0oh/echo_server.sml Secret
Last active Feb 17, 2016

Embed
What would you like to do?
module EchoServer
let start () = listen 1234
let listen port =
let (:ok, socket) = gen_tcp.listen port [(:packet, 0), (:active, false)]
in accept socket
let accept listen_socket =
let (:ok, socket) = gen_tcp.accept listen_socket
in do
spawn fn () -> echo socket
accept listen_socket
end
let echo socket =
match gen_tcp.recv socket 0 with
(:ok, data) ->
gen_tcp.send socket data
echo socket
(:error, :closed) ->
:ok
end
end
@Heinemark

This comment has been minimized.

Copy link

commented Aug 17, 2015

Brilliant code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.