Java network server and TIME_WAIT

后端 未结 3 1589
你的背包
你的背包 2021-01-15 20:17

I have run into a problem with a network server that receives signals from devices my company produces. The device will occasionally reuse the source port that it had just

3条回答
  •  庸人自扰
    2021-01-15 21:17

    The old not-recommended trick to avoid TIME_WAIT is to set SO_LINGER socket option to { 1, 0 } - the close then sends RST instead of doing normal flush/four-way exchange sequence, thus avoiding the TIME_WAIT all together (be warned - you might lose tail of what you still have in the send buffer.) I can't comment on whether this could be done in Java though.

    EDIT: Can you confirm with tcpdump that the clients really reuse source port numbers? If not, this might just be the classic case for SO_REUSEADDR listening socket option as Jon pointed out.

提交回复
热议问题