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

Ben Hood <>
Tue Jul 31 00:29:00 CEST 2007


Hi,

If I have a process that is already listening on a socket e.g.

loop(Sock,Length) ->
   case gen_tcp:recv(Sock, Length, -1) of
     {ok, Data} ->
         ......% Do something and calculate the next frame length
         loop(Sock, NewLength);
     _ ->
         ......
   end.

is there anyway to send an erlang message to this process? Do messages
get queued up until they are consumed by a receiving process, e.g.

loop(Sock,Length) ->
   case gen_tcp:recv(Sock, Length, -1) of
     {ok, Data} ->
         ......% Do something
         receive
             foo ->
              ......% Add something to the internal state of this process
         end,
         loop(Sock, NewLength);
     _ ->
         ......
   end.

Or can turn the loop into

receive
{tcp, Sock, Bin} ->
         ......

and somehow specify that I want to only take a frame of x bytes from
the tcp buffer?

Thx,

Ben



More information about the erlang-questions mailing list