TcpListener: How to listen on specific port on all interfaces?

后端 未结 1 1836
梦谈多话
梦谈多话 2020-12-19 03:33

There are three overloads for constructing a TcpListener:

  • public TcpListener(int port); (obsolete)
  • public TcpListener(IPEndPoint localEP)
相关标签:
1条回答
  • 2020-12-19 03:47

    Just bind to the IPAddress.Any - that's how this is usually done... not sure but it could be that you need to bind to IPAddress.IPv6Any too.

    This SO post suggests that you bind to every IP addresse explicitly - and this SO post has code on how to get all IP adresses...


    From MSDN:

    If you do not care which local address is assigned, specify IPAddress.Any for the localaddr parameter, and the underlying service provider will assign the most appropriate network address.


    From MSDN:

    IPAddress.Any Field

    Provides an IP address indicating that the server should listen for client activity on all network interfaces.

    0 讨论(0)
提交回复
热议问题