UDP multicast

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

UDP multicast

Adrian Sietsma
I know this is slightly specialized, but it is LuaSocket related :
Does anyone out there have experience with UDP multicast, particularly on
Windows ?

We have been testing LuaSocket with multicast, and have come across some
interesting behavior, and inconsistencies across platforms.
In particular, Windows XP seems to allow multiple sockets bound to a single
port (using SO_REUSEADDR) within a single app (console or windows), but not
between applications. This behavior is not specific to LuaSocket; I can
reproduce it in straight c.

Anyone else encountered this ?

Adrian

Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Tim Channon
Adrian Sietsma wrote:

> I know this is slightly specialized, but it is LuaSocket related :
> Does anyone out there have experience with UDP multicast, particularly
> on Windows ?
>
> We have been testing LuaSocket with multicast, and have come across some
> interesting behavior, and inconsistencies across platforms.
> In particular, Windows XP seems to allow multiple sockets bound to a
> single port (using SO_REUSEADDR) within a single app (console or
> windows), but not between applications. This behavior is not specific to
> LuaSocket; I can reproduce it in straight c.
>
> Anyone else encountered this ?

A bug was reported some time ago which if still present might explain
strangeness. Very easy to fix.

Correction should be in the next release.

I posted in group about this dated 03/10/2008 17:19

Err... checks copy of original email for date order, October.

Put this with quotes into a web search
"Re: Problem in Lua for Windows with UDP multicast receive"

Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Adrian Sietsma
> A bug was reported some time ago which if still present might explain
> strangeness. Very easy to fix.
>
> Correction should be in the next release.
>
> I posted in group about this dated 03/10/2008 17:19
>
> Err... checks copy of original email for date order, October.

Thanks. I found that thread that the other day, but that is not my problem.

My issue is more subtle - I am trying to get 2 applications to join the same
multicast group:port.
In any one app, I can bind multiple sockets to eg. INET_ADDR_ANY : 1700,
using SO_REUSE_ADDR, join them to the multicast group, and they all receive
group data. Exactly as documented.

What I can't do is then join that group:port from a second app; despite the
SO_REUSEADDR, the first bind(INET_ADDR_ANY , 1700) fails : not with an "in
use" error message, but a "permission denied".

This issue is not with LuaSocket - I am working with the latest beta (from
Diego) to check for consistent behavior across operating systems. I can
reproduce the problem in straight c.

In short : has anyone tried to run 2 applications which join the same
multicast group and port on windows or other OS ?

Adrian

Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Robert G. Jakabosky
On Monday 27, Adrian Sietsma wrote:
> In short : has anyone tried to run 2 applications which join the same
> multicast group and port on windows or other OS ?
>
> Adrian

Attached is C code for two programs mlisten.c & mcast.c

I was able to run 3 instances of mlisten.c, that joined the same multicast IP
listening on the same UDP port number, all on the same linux host.  Then I
started mcast.c on the same linux host which sent a message every second to
that multicast IP & port.

--
Robert G. Jakabosky

mcast.c (1K) Download Attachment
mlisten.c (2K) Download Attachment
netstat.log (410 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Mike Pall-2
In reply to this post by Adrian Sietsma
Adrian Sietsma wrote:
> What I can't do is then join that group:port from a second app; despite the
> SO_REUSEADDR, the first bind(INET_ADDR_ANY , 1700) fails : not with an "in
> use" error message, but a "permission denied".

You need a specific order of actions for Windows:
1. Create UDP socket
2. Set SO_REUSEADDR option
3. Bind addr = INADDR_ANY, port = multicast-port
4. IP_ADD_MEMBERSHIP multiaddr = multicast-group

See:
  http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx
  http://support.microsoft.com/default.aspx?scid=kb;en-us;131978

--Mike
Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Adrian Sietsma
In reply to this post by Robert G. Jakabosky
>
> Attached is C code for two programs mlisten.c & mcast.c
>
Thanks. That's practically identical to my test program set.

> I was able to run 3 instances of mlisten.c, that joined the same multicast IP
> listening on the same UDP port number, all on the same linux host.  Then I
> started mcast.c on the same linux host which sent a message every second to
> that multicast IP & port.
>
I get the same error (10013 : Permission denied.) at bind() in the second app .
I'll try a few different compilers tomorrow.

Adrian
Reply | Threaded
Open this post in threaded view
|

Re: UDP multicast

Adrian Sietsma
In reply to this post by Mike Pall-2
Mike Pall wrote:
>
> You need a specific order of actions for Windows:
> 1. Create UDP socket
> 2. Set SO_REUSEADDR option
> 3. Bind addr = INADDR_ANY, port = multicast-port
> 4. IP_ADD_MEMBERSHIP multiaddr = multicast-group
>
Exactly what I'm doing. Within a single app - no problem, I can bind as many
sockets (at least 3) exactly as documented.

The second copy of the app fails on bind().

> See:
>   http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx
>   http://support.microsoft.com/default.aspx?scid=kb;en-us;131978
>
> --Mike
>

Having read that ms stuff yet again, it would appear that the behaviour
depends on
a/ whether the first socket sets so_reuseaddr or not
b/ whether the listener is bound to a wildcard address (which is recommended
for udp multi).

I can try first binding without reuseaddr, then retry with reuseaddr if the
first bind returns "INUSE";
also bind to the local multicast i/f rather than INADDR_ANY.

But not tonight.
Thanks

Adrian