我听说过 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 套接字连接是否具有“保持活动状态"?
发布评论