简体   繁体   English

C#UDP服务器多个实例ipv6同一端口

[英]C# UDP server multiple instances ipv6 same port

I need multiple UDP servers, using the UDPClient class from .net. 我需要使用.net中的UDPClient类的多个UDP服务器。 For IPv4 i can achieve this by doing the following: 对于IPv4,我可以执行以下操作:

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. 它可以正常工作,我可以侦听端口53上的所有3个地址。对于IPv6,我需要执行相同的操作。 But it seems that i can listen on only 1 loopback address "::1". 但似乎我只能在1个环回地址“ :: 1”上侦听。

If i try to use "::2" i get a "The requested address is not valid in its context" error. 如果我尝试使用“ :: 2”,则会收到“请求的地址在其上下文中无效”错误。 Any help would be appreciated. 任何帮助,将不胜感激。

Thanks! 谢谢!

So, after some more investigation i found out that indeed, IPv6 has only 1 loopback address: "::1". 因此,经过更多调查,我发现IPv6确实只有1个环回地址:“ :: 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. 有一个叫做“本地链接”的小东西,它以“ fe80:...”开头,每个网络适配器都有一个唯一的地址,代表该特定网络适配器的回送地址。

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. 因此,我可以在:: 1端口53上打开一台服务器,或者我可以打开多台服务器,每个服务器都有一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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