Erlang 什么';gen_tcp:recv接收到的二进制文件是什么?
无论我是将数据包设置为0还是1、2、4,都会得到以下结果: gen_tcp:send(S1,term_to_二进制(“1”))。输出Erlang 什么';gen_tcp:recv接收到的二进制文件是什么?,erlang,gen-tcp,Erlang,Gen Tcp,无论我是将数据包设置为0还是1、2、4,都会得到以下结果: gen_tcp:send(S1,term_to_二进制(“1”))。输出 gen_tcp:send(S1,术语到二进制(a))。输出 gen_tcp:send(S1,术语到二进制(“abcd”))。输出 gen_tcp:send(S1,term_到_二进制(1))。输出 我的问题是: 1.是什么? 2.发送1而不是“1”,并获取没有数据包长度的二进制文件,如“131107,0,1”,为什么 我使用term\u to\u binary进行
gen_tcp:send(S1,术语到二进制(a))。输出
gen_tcp:send(S1,术语到二进制(“abcd”))。输出
gen_tcp:send(S1,term_到_二进制(1))。输出 我的问题是:
1.是什么?
2.发送1而不是“1”,并获取没有数据包长度的二进制文件,如“131107,0,1”,为什么 我使用term\u to\u binary进行编码,但不使用binary\u to\u term进行解码。使用term\u to\u binary时,将erlang值转换为外部term格式。 131是该格式的标题。107表示“下一个字节是字符串”,您可以在此处阅读: 我相信这里不需要术语到二进制。你可以用
loop(Socket) ->
case gen_tcp:recv(Socket, 0) of
{ok, Bin} ->
io:format("Bin=~p~n", [Bin]),
loop(Socket);
{error, Reason} ->
io:format("Reason=~p~n", [Reason])
end.
{env, [
{tcp_listen_options, [binary, {active, false}, {packet, 0}, {reuseaddr, true}, {backlog, 256}]},
{port, 5678}
]}
gen\u tcp:send(S1,>)
相反哦,是的,它说
分发版在跨节点边界发送消息时会隐式执行此操作。
gen_tcp:send(S1,<< "abcd" >>)