How to multicast using gen_udp in Erlang?

后端 未结 4 1222
梦如初夏
梦如初夏 2020-12-29 06:31

How do you use gen_udp in Erlang to do multicasting? I know its in the code, there is just no documentation behind it. Sending out data is obvious and simple. I

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 06:59

    Multicast sending has been answered, receipt requires subscription to the multicast group.

    It (still) seems undocumented, but has been covered on the erlang-questions mailing list before. http://www.erlang.org/pipermail/erlang-questions/2003-March/008071.html

        {ok, Socket} = gen_udp:open(Port, [binary, {active, false},
                                           {reuseaddr, true},{ip, Addr}, 
                                           {add_membership, {Addr, LAddr}}]).
    

    where the Addr is the multicast group, and LAddr is a local interface. (code courtesy of mog)

    The same options used above can be passed to inet:setopts including {drop_membership, {Addr, LAddr}} to stop listening to the group.

提交回复
热议问题