[英]Socket Error The requested address is not valid in its context
While Trying to Set the SocketOption using : 尝试使用设置SocketOption时:
listener.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new MulticastOption(ipAddress));
I am getting the following exception ; 我收到以下异常;
The requested address is not valid in its context
请求的地址在其上下文中无效
My listmer is: 我的名单管理员是:
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
and Ip is 3.212.xx 而Ip是3.212.xx
Is this a problem because of IP ? 这是因为IP造成的问题吗?
The Problem is in this statement: 问题在此语句中:
listener.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new MulticastOption(ipAddress));
MSDN outline this constructor as : MSDN将该构造函数概述为:
public MulticastOption(
IPAddress group
)
So the MulticastOption looks for a Group to broadcast but I had passed localIP and that was the problem. 因此,MulticastOption寻找一个要广播的组,但是我已经通过了localIP,这就是问题所在。
I instead I updated my Code: 相反,我更新了代码:
IPAddress ip = IPAddress.Parse("224.5.6.7");
Socket _socketServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
_socketServer.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new MulticastOption(ip));
_socketServer.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.