简体   繁体   English

套接字错误请求的地址在其上下文中无效

[英]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.

相关问题 WCF Tcp绑定“请求的地址在其上下文中无效”错误 - WCF Tcp Binding “The requested address is not valid in its context” Error “请求的地址在其上下文中无效” SocketException - “The requested address is not valid in its context” SocketException Socket.bind()在Win7上返回“请求的地址在其上下文中无效。” - Socket.bind() returns “The requested address is not valid in its context.” on Win7 当我尝试侦听端口时,请求的地址在其上下文中无效 - The requested address is not valid in its context when I try to listen a port 获取请求的地址在其上下文中无效。 在我的聊天应用程序中 - Getting The requested address is not valid in its context. in my chat application SocketException:请求的地址在上下文中无效 - SocketException: The requested address is not valid in the context HttpListener:请求的地址在此上下文中无效 - HttpListener: The requested address is not valid in this context 为什么我的服务器 TcpListener 使用本地地址而不使用公共地址? - 例外:请求的地址在其上下文中无效 - Why is my Server TcpListener Working with Local Address but not with Public Address? - Exception: The requested address is not valid in its context 面临错误 tcp 侦听器 SocketException:{0}System.Net.Sockets.SocketException (0x80004005):请求的地址在其上下文中无效 - Facing error tcp listener SocketException: {0}System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context 32feet .NET api拒绝连接“请求的地址在其上下文中无效” - 32feet .NET api refusing to connect “The requested address is not valid in its context”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM