UDP多播使用winsock API XP和Vista之间的差异 [英] UDP multicast using winsock API differences between XP and Vista

查看:292
本文介绍了UDP多播使用winsock API XP和Vista之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

$ c
$ b

  • 在Windows XP下,您必须呼叫 bind


  • 但是,在Windows vista下,您不能




p>这两个点中的任何一个在运行时都会导致套接字错误。



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

解决方案

$ c> setsockopt()调用您要申请 IP_ADD_MEMBERSHIP 并加入多播群组?



我刚刚在我的服务器框架中运行一些测试,我注意到我在Windows 7上调用 bind()(我没有Vista盒对手),然后我也可以如预期一样加入多播组,只要绑定地址和多播地址都有效。



然而,我不能使用 INADDR_ANY 调用bind(),因为这会导致多播组加入失败错误10022( WSAEINVAL ),如果多播组地址不是有效的多播地址,则调用失败,错误10049( WSAEADDRNOTAVAIL )。



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



[在XP测试后编辑]



在XP上, bind() c $ c> INADDR_ANY ,使用无效的多播地址是合法的。所以,我期望,你正在做的其中一个,因此它适用于XP而不是Vista / Win7。



所以,你得到什么错误和什么地址你绑定到?


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() before 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?

这篇关于UDP多播使用winsock API XP和Vista之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆