2

我对服务器端 tcp 绑定套接字的时间限制有疑问。

在我的调查中,我发现如果 tcp 客户端套接字向服务器发送关闭消息,客户端将在 2 个 MSL 后进入 TIME_WAIT 状态。

如果客户端套接字连接到服务器,但没有发送关闭消息。它也不会向服务器发送任何数据。服务器端套接字是否连续绑定此套接字并且在服务器关闭之前不会永远关闭它?

服务器端的 tcp 绑定套接字是否有有限的超时?

感谢您的阅读,并希望您的回复。

4

1 回答 1

0

No there's no time limit. A connected socket stays connected until the connection is closed.

If you want to make sure that both ends of a connection is still alive, you could add such a "is alive" message to your protocol, and if the the other doesn't answer within some time limit you can close the connection. There is also the builtin functionality of SO_KEEPALIVE socket option which will handle this for you, but the default timeout is two hours for that.

于 2013-05-20T13:48:47.067 回答