[erlang-questions] Sending message to process already listening on a socket

Hakan Mattsson hakan@REDACTED
Tue Jul 31 11:03:18 CEST 2007


If you use the socket option {active, once} you will
get the TCP data in the process mailbox. See the
man pages for inet and gen_tcp.

/Håkan

On Mon, 30 Jul 2007, Ben Hood wrote:

BH> Date: Mon, 30 Jul 2007 23:29:00 +0100
BH> From: Ben Hood <0x6e6562@REDACTED>
BH> To: erlang-questions@REDACTED
BH> Subject: [erlang-questions] Sending message to process already listening on
BH>     a socket
BH> 
BH> Hi,
BH> 
BH> If I have a process that is already listening on a socket e.g.
BH> 
BH> loop(Sock,Length) ->
BH>    case gen_tcp:recv(Sock, Length, -1) of
BH>      {ok, Data} ->
BH>          ......% Do something and calculate the next frame length
BH>          loop(Sock, NewLength);
BH>      _ ->
BH>          ......
BH>    end.
BH> 
BH> is there anyway to send an erlang message to this process? Do messages
BH> get queued up until they are consumed by a receiving process, e.g.
BH> 
BH> loop(Sock,Length) ->
BH>    case gen_tcp:recv(Sock, Length, -1) of
BH>      {ok, Data} ->
BH>          ......% Do something
BH>          receive
BH>              foo ->
BH>               ......% Add something to the internal state of this process
BH>          end,
BH>          loop(Sock, NewLength);
BH>      _ ->
BH>          ......
BH>    end.
BH> 
BH> Or can turn the loop into
BH> 
BH> receive
BH> {tcp, Sock, Bin} ->
BH>          ......
BH> 
BH> and somehow specify that I want to only take a frame of x bytes from
BH> the tcp buffer?
BH> 
BH> Thx,
BH> 
BH> Ben


More information about the erlang-questions mailing list