How to listen on multiple IP addresses?

后端 未结 6 1190
别那么骄傲
别那么骄傲 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 16:53

    You cannot bind a single socket to multiple endpoints. A SocketException (invalid argument error) occurs the second time you call Bind() for a given socket.

    As others have said, you can use IPAddress.Any to listen to the IPv4 addresses on the local machine. However, if you only want to listen on a subset of the available IP addresses, you'll have to create separate sockets.

提交回复
热议问题