How to listen on multiple IP addresses?

后端 未结 6 1335
别那么骄傲
别那么骄傲 2021-02-15 16:15

If my server has multiple IP addresses assigned to it, and I would like to listen to some (or all) of them, how do I go about doing that?

Do I need to create a new socke

6条回答
  •  没有蜡笔的小新
    2021-02-15 17:01

    I have worked on it, IPAddress.Any is not the proper way, It will bind any Suitable IP address. In my case I have 2 NIC and I couldn't trouble shoot the problem. When I added

    System.Net.IPAddress ipAddress = IPAddress.Parse("xxx.xxx.xxx.xxx");
    listener = new TcpListener(ipAddress, portNum);
    

    It worked fine.

提交回复
热议问题