使用套接字进行 UDP 多播时无法执行异常
当运行我在 XP 上创建的 C# 应用程序时,它运行得很好,但在 Windows 7 下,我收到以下错误:
“无法执行套接字上的操作,因为系统缺乏足够的缓冲区空间或队列已满”
我我正在执行以下操作:
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
IPAddress localIPAddr = IPAddress.Any;
EndPoint localEP = new IPEndPoint(localIPAddr, MulticastPort);
socket.Bind(localEP);
MulticastOption mcastOption = new MulticastOption(MulticastAddress, localIPAddr);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption);
byte[] bytes = new Byte[40960];
错误发生在倒数第二行 socket.SetSocketOption(...)
您会注意到我正在执行 UDP 多播,我需要为 Windows 7 做些什么才能允许这样做吗?
When running a C# app I created on XP it runs just fine, but under Windows 7, I get the following error:
"An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"
I am doing the following:
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
IPAddress localIPAddr = IPAddress.Any;
EndPoint localEP = new IPEndPoint(localIPAddr, MulticastPort);
socket.Bind(localEP);
MulticastOption mcastOption = new MulticastOption(MulticastAddress, localIPAddr);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption);
byte[] bytes = new Byte[40960];
The error happens on the second last line socket.SetSocketOption(...)
You'll notice I'm doing UDP multicasting, is there something I need to do for Windows 7 to allow this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIRC,加入多播组确实需要额外的权限,因为您正在修改内核级表。但我不记得那是什么特权。
IIRC, joining a multicast group does require an additional privilege since you are modifying a kernel level table. I cannot recall which privilege it is though.