How to multicast using gen_udp in Erlang?

后端 未结 4 1245
梦如初夏
梦如初夏 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 07:10

    I try to get this example running on my PC. What could happen, if I get always the message {error,eaddrnotavail} by opening the receive socket?

    Example 1: This works:

    {ok, Socket} = gen_udp:open(?PORT, [{reuseaddr,true}, {ip,?SERVER_IP},
                   {multicast_ttl,4}, {multicast_loop,false}, binary]),
    

    Example 2: Getting an runtime Error:

    {ok, Socket} = gen_udp:open(?PORT, [{reuseaddr,true}, {ip,?MULTICAST_IP},
                   {multicast_ttl,4}, {multicast_loop,false}, binary]),
    

    % --> {error,eaddrnotavail}

    -define(SERVER_IP, {10,31,123,123}). % The IP of the current computer
    -define(PORT, 5353).
    -define(MULTICAST_IP, {224,0,0,251}). 
    

提交回复
热议问题