Reputation: 1061
Is there an Erlang equivalent of the Java SocketChannel class? Need to be able to handle multiple client socket connections using one Erlang process.
Thanks!
Upvotes: 0
Views: 130
Reputation: 759
The gen_tcp interface allows you to interact quite easily with multiple sockets by a single Erlang process. Use the {active, once} socket option or, if you're feeling lucky, {active, true} socket option. For one/lots of very busy sockets, the latter can risk creating more messages to your Erlang process's mailbox than it can handle, hence {active, once} being the preferred option.
See: http://www.erlang.org/doc/man/inet.html and http://www.erlang.org/doc/man/gen_tcp.html
The option is usually specified in the gen_tcp:listen() or gen_tcp:connect() calls, though you can also change the 'active' mode setting on a socket using inet:setopts().
Upvotes: 3