【发布时间】:2014-05-16 15:49:10
【问题描述】:
我正在尝试使用 gen_tcp 模块。 有服务器端代码的例子,我有麻烦。
%% First, I bind server port and wait for peer connection
{ok, Sock} = gen_tcp:listen(7890, [{active, false}]),
{ok, Peer} = gen_tcp:accept(Sock),
%% Here client calls `gen_tcp:close/1` on socket and goes away.
%% After that I am tryin' send some message to client
SendResult = gen_server:send(Peer, <<"HELLO">>),
%% Now I guess that send is failed with {error, closed}, but...
ok = SendResult.
当我再次调用gen_tcp:send/2 时,第二次调用将按预期返回{error, closed}。但我想明白,为什么第一次调用成功?我错过了一些特定于 tcp 的细节吗?
这种奇怪的(对我来说)行为仅适用于 {active, false} 连接。
【问题讨论】: