Can two applications listen to the same port?

前端 未结 17 876
天涯浪人
天涯浪人 2020-11-22 03:50

Can two applications on the same machine bind to the same port and IP address? Taking it a step further, can one app listen to requests coming from a certain IP and the othe

17条回答
  •  伪装坚强ぢ
    2020-11-22 04:14

    I have tried the following, with socat:

    socat TCP-L:8080,fork,reuseaddr -
    

    And even though I have not made a connection to the socket, I cannot listen twice on the same port, in spite of the reuseaddr option.

    I get this message (which I expected before):

    2016/02/23 09:56:49 socat[2667] E bind(5, {AF=2 0.0.0.0:8080}, 16): Address already in use
    

提交回复
热议问题