UDP multicast using winsock API differences between XP and Vista
It seems to be that the implementation required to set up a UDP multicast socket has changed between windows XP and windows vista. Specifically:
Under windows XP, you must call
bind()
be开发者_开发技巧fore you can reference any multicast-specific socket options.However, under windows vista, you must not call
bind()
when dealing with multicast sockets.
Failing either of these two points results in a socket error at runtime.
Am I going crazy, or have other people seen this as well? Is there a better solution than conditional compilation of the bind() call?
What error are you getting from the setsockopt()
call that you make to apply IP_ADD_MEMBERSHIP
and join the multicast group?
I've just run some tests here with my server framework and I note that I DO call bind()
on Windows 7 (I don't have a Vista box to hand) and I can then also join a multicast group as expected as long as both the binding address and the multicast address are valid.
However I cannot call bind() with INADDR_ANY
, as that causes the joining of the multicast group to fail with error 10022 (WSAEINVAL
) and if the multicast group address isn't a valid multicast address the call fails with error 10049 (WSAEADDRNOTAVAIL
). Which all seems fair enough.
I'm booting an XP box now...
[Edited after testing on XP]
On XP it's legal to bind()
to INADDR_ANY
and it's legal to use invalid multicast addresses. So, I expect, you're doing one of those and it therefore works on XP and not on Vista/Win7.
So, what error are you getting and what address are you binding to?
I don't know about this specific question, but I do know that the network stack was rewritten from scratch for Vista
Well very old question, but does someone know how to check which version of winsock is present on the machine?
I have some old machines still using xp or server 2003. But testing for the windows version does not help, it seems it is possible to have an windows version 5.1, which is not accepting the bind before, and a machine having 5.2 Version accepting it.
精彩评论