Multicast

Reto Kramer <>
Thu Sep 2 21:39:35 CEST 2004


The following works on the OSX and Linux for me.  I had trouble opening 
the multicast socket on WinXP, but no patience to figure out the cause.

cheers,
- Reto

Open a multicast port with:
     Res = gen_udp:open(get_port(), [binary,
				    	{reuseaddr,true},
				    {ip,get_addr()},
				    {multicast_loop,true},
				    {add_membership,{get_addr(),
						     {0,0,0,0}}}]),

where
   get_addr() ->
       {ok, App} = application:get_application(),
       case application:get_env(App, addr) of
   	   {ok, Val} ->
	      Val;
	   undefined ->
	      ?ADDR
       end.
   get_port() -> ...

and the env key of the .app file is
    {env,          [{addr, {239,0,0,1}}, % the multicast ip addr
			     {port, 10042},       % the port we multicast at
			     {period, 1000}]},    % heartbeat interval in ms

Send packets with
     Packet = {node_name, node()},
     ok = gen_udp:send(State#state.socket,
		      get_addr(),
		      get_port(),
		      term_to_binary(Packet)),

and receive packets like this:
   receive
	{udp, Socket, IP, InPortNo, Packet} ->
	    {node_name, Node} = binary_to_term(Packet),

#

On Sep 2, 2004, at 12:03 PM, Martin J. Logan wrote:

> Is it possible to have multiple nodes on a single machine listening for
> the same multicast packets at the same time? How can this be
> accomplished within erts?
>
> Cheers,
> Martin
>




More information about the erlang-questions mailing list