【发布时间】:2014-10-28 19:03:12
【问题描述】:
当我从 c#-Part 发送数据:“hello world”时,我收到了数据并将其放入 test_out.txt,我在其中找到了“hello world”。应该是没有函数 binary_to_term 的吗?然后当然我得到了错误:tcp_closed 和客户端中的一些乱码。 ---->谢谢
[服务器]erlang-socket-code:
loop(Socket) ->
receive
{tcp,Socket,Bin} ->
io:format("server received binary = ~p~n",[Bin]),
file:write_file("test_out.txt", Bin),
B="welcome to unity3d:",
Response=[B | Bin],
io:format("server replying = ~p~n",[Response]),
gen_tcp:send(Socket,term_to_binary(Response)),
[客户端]c#-sockets-code
TcpClient client = new TcpClient("127.0.0.1", port);
byte[] data = System.Text.Encoding.UTF8.GetBytes(str);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
【问题讨论】:
-
明白了!我从 c#:TcpClient 发送了错误的数据,顺便说一句,我仍然想知道 test_out.txt 是如何得到字符串的:“hello world”
-
使用被动模式时:{avtive,false} and gen_tcp:recv/2, 1+1=2;当使用 {avtive ,true} 和 {tcp,sock,bin} 时,*&?·!