windows XP 和 Vista 之间使用 winsock API 的 UDP 多播差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1524946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:14:25  来源:igfitidea点击:

UDP multicast using winsock API differences between XP and Vista

c++windowssocketswindows-vistawinsock

提问by Thomi

It seems to be that the implementation required to set up a UDP multicast socket has changed between windows XP and windows vista. Specifically:

似乎在 Windows XP 和 Windows Vista 之间设置 UDP 多播套接字所需的实现已更改。具体来说:

  • Under windows XP, you mustcall bind()before you can reference any multicast-specific socket options.

  • However, under windows vista, you must notcall bind()when dealing with multicast sockets.

  • 在 Windows XP 下,您必须先调用,bind()然后才能引用任何特定于多播的套接字选项。

  • 但是在windows vista下,处理组播socket的时候一定不要调用bind()

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?

我疯了,还是其他人也看到了?有没有比 bind() 调用的条件编译更好的解决方案?

采纳答案by Len Holgate

What error are you getting from the setsockopt()call that you make to apply IP_ADD_MEMBERSHIPand join the multicast group?

您从setsockopt()申请IP_ADD_MEMBERSHIP和加入多播组的呼叫中得到什么错误?

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.

我刚刚用我的服务器框架在这里运行了一些测试,我注意到bind()我确实调用了 Windows 7(我手头没有 Vista 设备),然后我也可以按预期加入多播组,只要绑定地址和组播地址有效。

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.

但是,我无法使用 调用 bind() INADDR_ANY,因为这会导致加入多播组失败并出现错误 10022 ( WSAEINVAL),如果多播组地址不是有效的多播地址,则调用失败并出现错误 10049 ( WSAEADDRNOTAVAIL)。这一切似乎都足够公平。

I'm booting an XP box now...

我现在正在启动一个 XP 盒子...

[Edited after testing on XP]

[在XP上测试后编辑]

On XP it's legal to bind()to INADDR_ANYand 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.

在XP是合法的bind()INADDR_ANY,它是合法的使用无效的多播地址。所以,我希望,您正在执行其中之一,因此它适用于 XP,而不适用于 Vista/Win7。

So, what error are you getting and what address are you binding to?

那么,您遇到了什么错误以及您绑定到哪个地址?

回答by Anders

I don't know about this specific question, but I do know that the network stack was rewritten from scratch for Vista

我不知道这个具体问题,但我知道网络堆栈是为 Vista 从头开始​​重写的

回答by nop_0x00

Well very old question, but does someone know how to check which version of winsock is present on the machine?

很好很老的问题,但是有人知道如何检查机器上存在哪个版本的 winsock 吗?

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.

我有一些旧机器仍在使用 xp 或 server 2003。但是测试 windows 版本并没有帮助,似乎有可能有一个 windows 5.1 版本,它以前不接受绑定,而 5.2 版本的机器接受它.