TCP 套接字连接是否具有“保持活动状态"? [英] Does a TCP socket connection have a "keep alive"?
问题描述
我听说过 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.
也就是说,在不实际发送数据的情况下很难检测到断开的连接(断开的,例如路由器死机等,而不是关闭),因此大多数应用程序每隔一段时间就会进行某种乒乓反应以确保连接实际上仍然有效.
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 套接字连接是否具有“保持活动状态"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!