LAN resolver revisited

5 visualizações
Ir para a primeira mensagem não lida

Steven Robertson

não lida,
14/09/2010, 16:47:0414/09/10
para playdar
The Programming Erlang book has an example of UDP broadcast with a
different code example so I've been trying this in the hope of having
Playdar on Windows behave more as expected. Some success, but not
using IGMP and using 255.255.255.255 as the broadcast address and
using different port for sending and receiving messages. This may not
be appropriate. I'd really like to know. In my test it does work
passing messages between Erlang shell on a Windows 7 and Arch Linux
set-up.

Here's the code if anyone is able to advise:

-module(broadcast).
-compile(export_all).

-define(SEND_FROM_PORT, 60212).
-define(LISTEN_TO_PORT, 60210).
-define(BROADCAST_ADDR, {255,255,255,255}).

send(IoList) ->
{ok, S} = gen_udp:open(?SEND_FROM_PORT, [{broadcast, true}]),
gen_udp:send(S, ?BROADCAST_ADDR, ?LISTEN_TO_PORT, IoList),
gen_udp:close(S).

listen() ->
{ok, _} = gen_udp:open(?LISTEN_TO_PORT),
loop().

loop() ->
receive
Any ->
io:format("received:~p~n", [Any]),
loop()
end.

Steven Robertson

não lida,
14/09/2010, 18:06:5114/09/10
para playdar
An example using above code in two Erlang shells on same or separate machines.

Erlang shell 1:

> c(broadcast).
> broadcast:listen().

Erlang shell 2:

> c(broadcast).
> broadcast:send("hello").

The listening shell should receive the "hello" message.
Responder a todos
Responder ao autor
Reencaminhar
0 mensagens novas