Can two applications listen to the same port?

前端 未结 17 906
天涯浪人
天涯浪人 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:40

    Yes Definitely. As far as i remember From kernel version 3.9 (Not sure on the version) onwards support for the SO_REUSEPORT was introduced. SO_RESUEPORT allows binding to the exact same port and address, As long as the first server sets this option before binding its socket.

    It works for both TCP and UDP. Refer to the link for more details: SO_REUSEPORT

    Note: Accepted answer no longer holds true as per my opinion.

提交回复
热议问题