C#UDP服务器多个实例ipv6同一端口 [英] C# UDP server multiple instances ipv6 same port

查看:178
本文介绍了C#UDP服务器多个实例ipv6同一端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要多个UDP服务器,使用来自.net的UDPClient类. 对于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));

它有效,我可以在端口53上侦听所有3个地址. 我需要对IPv6做同样的事情.但似乎我只能在1个环回地址":: 1"上收听.

如果我尝试使用":: 2",则会收到请求的地址在其上下文中无效"错误.任何帮助将不胜感激.

谢谢!

解决方案

因此,经过更多调查后,我发现IPv6确实只有1个环回地址:":: 1".

但是!有一个叫做本地链接"的小东西,它以"fe80:..."开头,并且每个网络适配器都有一个唯一的地址,代表该特定网络适配器的回送地址. /p>

因此,我可以在:: 1端口53上打开一台服务器,或者我可以打开多台服务器,每个服务器都有一个.

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.

这篇关于C#UDP服务器多个实例ipv6同一端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆