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

Matthias Lang matthias@REDACTED
Tue Jul 31 10:32:44 CEST 2007


1. Yes, messages are queued up until consumed.

2. Take a look at the {active, once} option for TCP sockets. It's
   documented on the inet manpage.

3. If your message handling starts getting complicated and you
   complicate your code to try and prevent blocking, then that's
   often a sign that you're trying to get one process to solve a
   problem which would be more cleanly solved by two or more processes.

Matthias

--------------------

Ben Hood writes:
 > 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
 > _______________________________________________
 > erlang-questions mailing list
 > erlang-questions@REDACTED
 > http://www.erlang.org/mailman/listinfo/erlang-questions
 > 



More information about the erlang-questions mailing list