如何用TcpListener同时监听多个网卡的IP地址
其实很简单,把特定的IPAddress改成 IPAddress.any 就可以了.
IPAddress ipAddr = IPAddress.Parse(ip);
if (ip == "0.0.0.0")
{
ipAddr = IPAddress.Any;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
IPEndPoint localEP = new IPEndPoint(ipAddr, port);
if (tcpListener != null)
{
tcpListener.Stop();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
tcpListener = new TcpListener(localEP);
Thread t = new Thread(new ParameterizedThreadStart(this.ThreadListen));
t.Start(tcpListener);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Thread t = new Thread(new ParameterizedThreadStart(this.ThreadListen));
t.Start(tcpListener);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
QQ:273352165
evlon#126.com
转载请注明出处。