小编S J*_*ton的帖子

C#IPv4/IPv6不可知套接字监听器

我试图弄清楚如何在C#中创建一个与协议无关的套接字侦听器 - 它应该抓取IPv4和IPv6请求.我在Google上找到的所有内容似乎都是C.尝试类似于我在C中看到的内容,我尝试了以下代码:

/*Socket*/ m_sock = null;
/*IPAddress*/ m_addr = null;
/*int*/ m_port = port; /*port passed to function*/
/*int*/ m_listenqueue = listen_queue_size; /*also passed to function, number of pending requests to allow before busy*/
IPAddress[] addrs = Dns.GetHostEntry("localhost").AddressList;
if(family == null) m_addr = addrs[0];
else
{
    foreach(IPAddress ia in addrs)
    {
        if(ia.AddressFamily == family) /*desired address family also passed as an argument*/
        {
            m_addr = ia;
            break;
        }
    }
}
if(m_addr == null) throw new Exception(this.GetType().ToString() + ".@CONSTRUCTOR@: Listener …
Run Code Online (Sandbox Code Playgroud)

c# sockets ipv4 ipv6

2
推荐指数
1
解决办法
3404
查看次数

标签 统计

c# ×1

ipv4 ×1

ipv6 ×1

sockets ×1