Simple question...
This code ..
client() ->
SomeHostInNet = "localhost" % to make it runnable on one machine
{ok, Sock} = gen_tcp:connect(SomeHostInNet, 5678,
[binary, {packet, 0}]),
ok = gen_tcp:send(Sock, "Some Data"),
ok = gen_tcp:close(Sock).
is very clear except that I don't quite understand what [binary, {packet,0}] means ? Any one cares to explain ?
MadSeb
As per the gen_tcp:connect documentation:
[binary, {packet, 0}]
is the list of options that's passed to the connect function.binary
means that the data that is sent/received on the socket is in binary format (as opposed to, say, list format.{packet, 0}
, is a little confusing and it doesn't appear to be covered in the documentation. After talking to some knowledgeable chaps in #erlang on Freenode, I found that the packet
option specifies how many bytes indicate the packet length. Behind the scenes, the length is stripped from the packet and erlang just sends you the packet without the length. Therefore {packet, 0}
is the same as a raw packet without a length and everything is handled but the receiver of the data. For more information on this, check out inet:setopts.Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With