gen_tcp and message handling
Daniel Ginsburg
dginsburg@REDACTED
Thu Jan 6 10:46:28 CET 2005
On Wed, 05 Jan 2005 21:36:54 -0600, James Hague <james@REDACTED> wrote:
> Once you open a port with gen_tcp, by default all messages to that
> port are sent to the controlling process as normal Erlang messages.
> You use the receive statement to get them. Slick!
>
> When sending messages this isn't true. You send a message via
> gen_tcp:send/2, not via the bang operator. Is there a reason that
> you can't simply send messages to the port returned by
> gen_tcp:connect? The main reason I'm asking is that it would be nice
> to register the Erlang port returned by gen_tcp:connect, then send
> messages to that name, rather than having to pass the TCP port number
> all around.
>
> James
>
I'd like to see that too. OTOH, it would suffer from the same problem
- no flow control. You could send your messages faster than other end
of tcp connection could read data. What I would really like to see are
messages {tcp_new_conn, Socket}, {tcp_ready_to_send, Socket} etc. (we
already have an equivalent of {tcp_ready_to_recv, Socket} in form of
{active, once} sockets). Given those primitives it would be very easy
to use gen_tcp with gen_servers avoiding tricks like separate
nonbehaving acceptor processes.
--
dg
More information about the erlang-questions
mailing list