TCP receive in gen_server

David N Murray dmurray@REDACTED
Fri May 7 22:11:18 CEST 2010


Hi,

I have a gen_server that opens a socket to another (non-erlang) process
that it talks to over a TCP socket.  I open the socket with

    case gen_tcp:connect(Host, Port, [list, inet]) of

and I expect that I will see data from the socket showing up in my
handle_info({tcp, Socket, Data}) function.  I have another
gen_server that performs the writes to the Socket.  After the reader
process connects, it passes a message to the writer with the Socket
returned from the connect().

Everything seems to be working fine, especially reconnecting after a crash
(the supervisor/gen_server combination is great!). However, after the
initial handshake the only time I receive data via handle_info is after I
write something to the socket a second time.  This results in a delayed
conversation: write1, receive informational messages that were sitting in
socket (not reply to write1), write2, receive reply to write1, write3,
receive reply to write2, etc.  I know the reply is being immediately
passed back from the server process I'm connecting; I can see it in that
program's log.

Am I missing something about how this should work?

TIA,
Dave



More information about the erlang-questions mailing list