【发布时间】:2016-11-14 08:56:44
【问题描述】:
我在远程服务器上运行tcpdump -i eth0 -vv ip6 并查看此类数据包
11:10:36.712804 IP6 (hlim 1, next-header UDP (17) payload length: 103) fe80::f816:3eff:fe94:a348.57100 > ff3c::8500:2345.57100: [udp sum ok] UDP, length 95
但是当我打开 Socket 时
{ok, Socket} = gen_udp:open(57100, [binary, {active, true}, {ip, any}, inet6, {reuseaddr, true}])
或
{ok, Socket} = gen_udp:open(57100, [binary, {active, true}, {ip, any}, inet6, {multicast_ttl, 225}, {multicast_loop, false}, {reuseaddr, true}])
或
{ok, Socket} = gen_udp:open(57100, [binary, {active, true}, {ip, {65340,0,0,0,0,0,34048,9029}}, inet6, {multicast_ttl, 225}, {multicast_loop, false}, {reuseaddr, true}])
{65340,0,0,0,0,0,34048,9029} = <<"FF3C:0000:0000:0000:0000:0000:8500:2345">>
并以这种方式等待消息
subscribe_on_stream() ->
%% {ok, Socket} = gen_udp:open(57100, [binary, {active, true}, {ip, IP}, inet6, {multicast_ttl, 225},
%% {multicast_loop, false}, {reuseaddr, true}]),
{ok, Socket} = gen_udp:open(Port, [binary, {active, true}, {reuseaddr, true}]),
io:format("self: ~p line: ~p~n", [self(), ?LINE]),
subscribe_loop(Socket).
subscribe_loop(Socket) ->
receive
Any ->
io:format("~p~n", [Any])
end.
【问题讨论】:
-
你能提供更多的代码吗?
receive ... end.放在哪里? -
subscribe_on_stream() -> %% {ok, Socket} = gen_udp:open(57100, [binary, {active, true}, {ip, IP}, inet6, {multicast_ttl, 225}, %% {multicast_loop, false}, {reuseaddr, true}]), {ok, Socket} = gen_udp:open(Port, [binary, {active, true}, {reuseaddr, true}]), io:format("self: ~p line: ~p~n", [self(), ?LINE]), subscribe_loop(Socket). subscribe_loop(Socket) -> receive Any -> io:format("~p~n", [Any]) end. -
@ipinak 我在其他进程中获取资源并没有出错