TCPListener ipv4和ipv6 [英] TCPListener both ipv4 and ipv6

查看:141
本文介绍了TCPListener ipv4和ipv6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建一个Tcp套接字,该套接字支持侦听IPv4作为IPv6地址.我正在使用以下代码.

Hi,

I''m trying to create a Tcp Socket that supports listening to an IPv4 as an IPv6 adress. I am using the following code.

_listener = new TcpListener(IPAddress.Any, port);
_listener.AllowNatTraversal(true);                      
_listener.Start();



当我在Windows Server 2003 SP2上执行此代码时,这会导致SocketException并显示以下异常消息:在getsockopt或setsockopt调用中指定了未知,无效或不受支持的选项或级别"



When I execute this code on a Windows Server 2003 SP2 this results in an SocketException with the following exception message: "An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call"

does anyone can explain what is going on?

推荐答案

我还没有尝试过任何IPv6的东西,但是我相信如果您需要启动第二个侦听器,想要同时支持IPv4和IPv6. IPAddress.Any特定于IPv4. IPv6等效为IPAddress.IPv6Any.
I haven''t tried any IPv6 stuff yet, bu I believe you may have to start a second listener if you want to support both IPv4 and IPv6. IPAddress.Any is specific to IPv4. The IPv6 equivilent is IPAddress.IPv6Any.


这篇关于TCPListener ipv4和ipv6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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