我认为这将是一项简单的任务,已经变成了一场噩梦 .

到目前为止,我需要在特定链路本地IPv6地址上的端口8888上创建UDP侦听器 .

执行以下行时,抛出异常:

_udpSoc = new UdpClient(MONITOR_INPUT_EVENT_SOCKET, AddressFamily.InterNetworkV6);

(其中MONITOR_INPUT_EVENT_SOCKET是值为8888的const int)

在试图寻找支持后,我甚至发现an MSDN article描述完全相同的一行 .

抛出的SocketException是“请求的地址在其上下文中无效”,ErrorCode为10049,堆栈跟踪为:

at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.UdpClient..ctor(Int32 port, AddressFamily family)
at [my code...]

或者,如果我将问题行更改为:

_udpSoc = new UdpClient(_groupEp);

(其中_groupEp是IPEndPoint设置为IPAddress.Any,ScopeId设置正确的接口,端口为MONITOR_INPUT_EVENT_SOCKET)

...并获得“请求的地址在其上下文中无效”的异常,具有与以前相同的ErrorCode和堆栈跟踪 .

出了什么问题?