C# UDP server multiple instances ipv6 same port

我与影子孤独终老i 提交于 2020-01-07 02:55:29

问题


I need multiple UDP servers, using the UDPClient class from .net. For IPv4 i can achieve this by doing the following:

var udpServer1 = new UdpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 53));
var udpServer2 = new UdpClient(new IPEndPoint(IPAddress.Parse("127.0.0.2"), 53));
var udpServer3 = new UdpClient(new IPEndPoint(IPAddress.Parse("127.0.0.3"), 53));

And it works, i can listen on all 3 addresses on port 53. I need to do the same for IPv6. But it seems that i can listen on only 1 loopback address "::1".

If i try to use "::2" i get a "The requested address is not valid in its context" error. Any help would be appreciated.

Thanks!


回答1:


So, after some more investigation i found out that indeed, IPv6 has only 1 loopback address: "::1".

BUT! There is a little thing called a "link-local" address, that starts with "fe80:..." and you have 1 of those unique to each of your network adapters, that represents the loopback address for that specific network adapter.

So, i can open a server on ::1 port 53, or i can open multiple servers, one for each of the network adapters i do have.



来源:https://stackoverflow.com/questions/43779933/c-sharp-udp-server-multiple-instances-ipv6-same-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!