as you probably know, there three modes of gen_tcp. {active, false}, {active, true} and {active, once}.
I have read some documents about {active, false}, {active, true} and {active, once}. However, I didn't get it.
What is difference between {active, false} and {active, true} and {active, once}?
Could you please explain plainly?
{active, false}
You have to read a chunk of data from the socket by calling gen_tcp:recv().
{active, true}
Erlang automatically reads chunks of data from the socket for you and gathers the chunks into a complete message and puts the message in the process mailbox. You read the messages using a
receiveclause. If some hostile actor floods your mailbox with messages, your process will crash.{active, once}
Equivalent to
{active, true}for the first chunks of data read from the socket, then{active, false}for any subsequent chunks of data.You also need to understand how specifying
{packet, N}influences things. See here: Erlang gen_tcp not receiving anything.