[socket]尴尬的close_wait状态以及应对策略([socket] awkward close_wait status and coping strategies).docVIP

  • 36
  • 0
  • 约1.2万字
  • 约 15页
  • 2017-09-03 发布于河南
  • 举报

[socket]尴尬的close_wait状态以及应对策略([socket] awkward close_wait status and coping strategies).doc

[socket]尴尬的close_wait状态以及应对策略([socket] awkward close_wait status and coping strategies)

[socket]尴尬的close_wait状态以及应对策略([socket] awkward close_wait status and coping strategies) [Socket] awkward CLOSE_WAIT status and coping strategies Writers Edition This article assumes that you are familiar with the Socket, C++, and TCP states. Zheng Yun @ Linktone First draft Chapter content The reason for the generation of the CLOSE_WAIT state Reuse local addresses and ports Calm down or force off? summary Abstract: This article explains why the socket connection is locked in the CLOSE_WAIT state and by what measures to avoid this situation. Not long ago, my Socket Client program ran into a very embarrassing error. It should have continued to send data to the server on a socket long connection. If the socket connection is broken, the program will automatically retry the connection. One day, discovery programs are constantly trying to build connections, but they always fail. Check with netstat, the program has thousands of socket connections, in the CLOSE_WAIT state, so that reached the upper limit, so can not establish a new socket connection. Why is that so? Why are they all in the CLOSE_WAIT state? The reason for the generation of the CLOSE_WAIT state First of all, we know that if our Client program is in the CLOSE_WAIT state, it will indicate that the socket is passively closed! Because if the Server side is actively breaking the current connection, then the two sides shut down the TCP connection, a total of four packet: Server FIN Client Server ACK Client At this point, the Server side is in the FIN_WAIT_2 state; and our program is in the CLOSE_WAIT state. Server FIN Client At this point, Client sends FIN to Server, and Client to the LAST_ACK state. Server ACK Client Server responds to ACK, and then the Client socket is really in the CLOSED state. Our program is in the CLOSE_WAIT state, rather than LAST_ACK, indicating that no FIN to Server, it may be in close connection before there are a lot of data to be sent or other things to do, cause not the FIN pa

文档评论(0)

1亿VIP精品文档

相关文档