Created
October 19, 2019 12:58
-
-
Save PeteDevoy/30476594a1488c78106af1efe7de44bd to your computer and use it in GitHub Desktop.
Erlang gen_tcp {packet, line} with null byte line delimiter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Open two shells | |
%In first shell | |
{ok, ListenSock} = gen_tcp:listen(8091, [{active,true}, binary]). | |
{ok, AcceptSock} = gen_tcp:accept(ListenSock). | |
%it waits, so proceed to connect in second shell: | |
%In second shell | |
{ok, ClientSock} = gen_tcp:connect({127,0,0,1}, 8091, [binary, {active, true}]). | |
%In first shell | |
Opts = [{active, true}, {packet, line}, {line_delimiter, $\0}]. | |
ok = inet:setopts(AcceptSock, Opts). | |
%In second shell | |
gen_tcp:send(ClientSock, "abcd\0efg\0"). | |
%In first shell | |
flush(). | |
%Result: | |
%Shell got {tcp,#Port<0.333>,<<97,98,99,100,0>>} | |
%Shell got {tcp,#Port<0.333>,<<101,102,103,0>>} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment