问题描述
我听说过HTTP keep-alive但是现在我想打开与远程服务器的套接字连接。
现在这个套接字连接将永远保持打开状态,或者是否存在与之关联的超时限制类似于HTTP keep-alive?
I have heard of HTTP keep-alive but for now I want to open a socket connection with a remote server.
Now will this socket connection remain open forever or is there a timeout limit associated with it similar to HTTP keep-alive?
推荐答案
TCP套接字在关闭之前一直保持打开状态。
TCP sockets remain open till they are closed.
也就是说,在没有实际发送数据的情况下,很难检测出连接断开(断路,如路由器死机等,而不是关闭),因此大多数应用程序都会进行某种ping / pong反应。通常只是为了确保连接仍然存在。
That said, it's very difficult to detect a broken connection (broken, as in a router died, etc, as opposed to closed) without actually sending data, so most applications do some sort of ping/pong reaction every so often just to make sure the connection is still actually alive.
这篇关于TCP套接字连接是否具有“保持活动状态”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!