[erlang-questions] upnp device discovery

Joe Armstrong <>
Thu Sep 23 15:14:05 CEST 2010


I came to the same conclusion - pretty easy really - now I just have
to eat up the xml and figure out what it means.

/Joe


On Wed, Sep 22, 2010 at 3:14 PM, Alexander Harju
<> wrote:
>> Has anybody got some erlang code for upnp device disovery?
>>
>> /Joe
>>
>
> Hi.
> I was just experimenting with last weekend.
>
> For discovery you just have to send the discovery message to multicast
> address 239.255.255.250:1900
>
> -define(UPNP_DISCOVER,
>    "M-SEARCH * HTTP/1.1\r\n"
>    "Host: 239.255.255.250:1900\r\n"
>    "Man: \"ssdp:discover\"\r\n"
>    "ST: upnp:rootdevice\r\n"
>    "MX: 3\r\n\r\n").
>
>
> {ok, S} = gen_udp:open(1900, [{reuseaddr,true}]),
>
> gen_udp:send(S, {239,255,255,250}, 1900, ?UPNP_DISCOVER),
> receive
>    {udp, S, _, _, Msg0} ->
>        [_|Msg] = lists:reverse(Msg0),
>        io:format("~s~n", [lists:reverse(Msg)])
>    after 5000 ->
>           ok
> end.
>
> The rest is "just" handling the UPnP massive SOAP protocol. xmerl and inets
> or yaws, erlsom.
>
>
> You can also listen to UPnP multicasts like this:
>
> Opts = [{multicast_loop,false},
>              {multicast_if,{0,0,0,0}},
>              {multicast_ttl,4}],
>
> {ok, S} = gen_udp**:open(1900, Opts),
> inet:setopts(S, [{add_membership, {Ip, {0,0,0,0}}}]),
>
> receive
>    {udp, S, ...
>
> BR
> // Alex
>


More information about the erlang-questions mailing list