开发者

Fail to open a socket for multicast

开发者 https://www.devze.com 2022-12-13 20:01 出处:网络
I have problems to open an multicast socket in Erlang to receive messages: 88> gen_u开发者_如何学编程dp:open(5353,[{reuseaddr, true}, {ip,{224,0,0,251}},{multicast_ttl,4},{multicast_loop,false},bi

I have problems to open an multicast socket in Erlang to receive messages:

88> gen_u开发者_如何学编程dp:open(5353,[{reuseaddr, true}, {ip,{224,0,0,251}},{multicast_ttl,4},{multicast_loop,false},binary]).
{error,eaddrnotavail}

I checkt diffrent IP addresses and ports and the option {active, false}, but nothing helps. What could be the reason?

Thanks, Matthias.


Have you tried adding the option {add_membership, {Addr, LAddr}} where:

  1. Addr is the multicast group in question (e.g. 224.0.0.251)
  2. LAddr is a local interface (e.g. 0.0.0.0 for the default one)

1> gen_udp:open(5353,[{reuseaddr, true}, {add_membership, {{224, 0,0, 251}, {0, 0, 0, 0}}}, {ip,{224,0,0,251}},{multicast_ttl,4},{multicast_loop,false},binary]).

{ok,#Port<0.454>}

0

精彩评论

暂无评论...
验证码 换一张
取 消