假设这是一个简单的无状态服务器。
如果服务器在处理请求并写回响应后关闭连接,则处于
CLOSE_WAIT
状态的连接数一定过多。如果让客户端先关闭连接,如果客户端不关闭它们,服务器端可能会有太多事件连接。
那么遇到这种情况该如何处理呢?我应该使用 1 或 2 还是其他?
最佳答案
If server close connection after handling the request and writing back the response, there must be too many connections in CLOSE_WAIT status.
不会,但是会有很多 TIME_WAIT 状态。
If let client close connection first, there might be too many active connections in server side if the client doesn't close them.
所以服务器应该使用读取超时。
一般来说,服务器最好是接收第一个关闭的服务器。这样,TIME_WAIT 状态就会堆积在客户端,而不是服务器,并且客户端不会有大量连接,因此不会出现任何问题。
关于c - TCP 让服务器先关闭连接 让客户端先关闭连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44019127/