TCP/IP Stream and recv?
Javier París Fernández
paris@REDACTED
Wed Feb 8 20:12:34 CET 2006
Hi,
On Wed, Feb 08, 2006 at 06:36:16PM +0000, Chris Campbell wrote:
> Hi,
>
> This may be a misunderstanding of tcp but here goes. The following
> client sends two messages to a client one after the other, then waits
> 5 seconds and exits. The server waits for 1 second after accepting a
> connection, then does 1 call to recv. It only retrieves the first
> message. Is this Erlang specific or TCP behaviour? My understanding
> of tcp is that it's a stream and recv may return both messages
> (ignoring fragmentation for the moment).
Yes, it works that way.
> I have only used tcp with single requests like HTTP so far. I'm now
> toying with something that will send messages back and forth hence why
> it's important to know if recv will pull a single message or it just
> pulls everything to make account for this in the protocol parser.
In your case it's due to the use of {packet, 4}, which is a feature
added in Erlang to support sending messages using tcp, insted of
having a continuous stream. If you want to receive everything in one
call you hace to use either raw or 0.
Regards.
More information about the erlang-questions
mailing list