我有 .NET TCP Sender 发送到 Erlang 接收器。::1
.NET 组件在解析 .NET 时喜欢使用 IPv6 地址localhost
。我不太确定如何让 Erlang 使用 gen_tcp 监听 IPv6 地址。这是我的尝试。我是在告诉错误的套接字进行监听吗?谢谢!
listen(Config) ->
PortString = Config#cfg.eventbusport,
GoodPort = check_int(PortString),
Port = if GoodPort ->
list_to_integer(PortString);
true ->
?DEFAULT_PORT
end, %% IPv6 here --->
{ok, XSocket} = gen_tcp:listen(Port, [binary, {packet, line}, {active, false}, {reuseaddr, true}, inet6, {ip, {0,0,0,0,0,0,0,1}}])
end,
accept(XSocket, Config).
accept(LSocket, Config) ->
case gen_tcp:accept(LSocket) of
{ok, Socket} ->
spawn_link(fun() -> loop(Socket, Config) end),
accept(LSocket, Config);
{error, closed} ->
logger("Accept: Closed socket.",[],1),
listen(Config)
end.
loop(Socket, Config) ->
case inet:setopts(Socket, [{recbuf, 64000}]) of
ok ->
case gen_tcp:recv(Socket, 0) of
{ok, Data} ->
SplitData = binary:split(Data,?CRLF,[global]),
discrim(SplitData, Config),
loop(Socket, Config);
{error, closed} ->
logger("Loop: Closed socket.",[],1),
ok
end;
{error, Reason} ->
logger("ERROR: Couldn't set the recbuf to 64k! Because ~p",[Reason],1)
end.