Let two UDP-servers listen on the same port?

前端 未结 3 1267
你的背包
你的背包 2020-12-06 00:56

I have a client which sends data via UDP-broadcast. (To let\'s say 127.0.0.255:12345)

Now I want to have multiple servers listening to this data. To do so on a local

3条回答
  •  误落风尘
    2020-12-06 01:42

    You will have to bind the socket in both processes with the SO_REUSEPORT option. If you don't specify this option in the first process, binding in the second will fail. Likewise, if you specify this option in the first but not the second, binding in the second will fail. This option effectively specifies both a request ("I want to bind to this port even if it's already bound by another process") and a permission ("other processes may bind to this port too").

    See section 4.12 of this document for more information.

提交回复
热议问题