[erlang-questions] How does Erlang TCP determine the end of a TCP stream?
code wiget
codewiget95@REDACTED
Tue Oct 31 17:10:49 CET 2017
Vimal and Scott,
I would like to clarify quickly that this is not a coincidence, and that I am processing ~500 messages/min over 1 socket connected to 1 client server and all of the messages are “framed” properly. There is something in the OTP that is framing the packets.
Vimal - I am using {active, once}. And I like when it comes in as a full packet, so I do not want to change anything that could eliminate that behavior. When I get a handle info and ensure that the data is the right length in the guard, I can then do validation on the packet (we use a start code and stop code of 4 bytes) to ensure the validity of the packet from there. Having a stream and using gen_tcp:recv would complicate the gen_server in my opinion and it is clean now.
I just went to the Erlang man pages on the set_opts, and it seems like {active, once} works for my purposes:
"If the value is once ({active, once}), onedata message from the socket is sent to the process…..
Use active mode only if your high-level protocol provides its own flow control (for example, acknowledging received messages) or the amount of data exchanged is small.”
It does not define how long “one data message” is, but from reading on, it seems like the small size of my packets is the reason it is working. All of the packets I am expecting are < 500 bytes.
This settles this a bit for me, I can sleep at night, but we are working on an assumption about erlang’s “one data message”.
If anyone can elaborate on this, or has some more in depth knowledge, I would greatly appreciate your expertise.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171031/18bfc114/attachment.htm>
More information about the erlang-questions
mailing list