简体   繁体   中英

C# UDP server multiple instances ipv6 same port

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM