Why does my Client Server Socket Connection Keep Disconnecting
I have a client server application writter in C# .NET using Sockets.
I often get log messages (say about 4 per hour) saying this message,
An existing connection was forcibly closed by the remote host
In this case here the error is occuring on the 'server' side.
I decided to use wireshark to analyse what is occuring, and I get this. There are no delays, this is all happening within a couple of seconds.
Server > Client [PSH, ACK] Seq=55653 Ack=4472 Win=63940 Len=148
Client > Server [ACK] Seq=4472 Ack=55801 Win=4038 Len=0
Server > Client [PSH, ACK] Seq=55801 Ack=4472 Win=63940 Len=148
Client > Server [ACK] Seq=4472 Ack=55949 Win=4001 Len=0
Server > Client [PSH, ACK] Seq=55949 Ack=4472 Win=63940 Len=142
Client > Server [PSH, ACK] Seq=4472 Ack=55949 Win=4001 Len=31
Client > Server [RST, ACK] Seq=4503 Ack=55949 Win=0 Len=0
So the client and server are sending stuff between themselves (PSH) and acknowledging stuff (ACK). All of a sudden a RST is occuring. This according to wikipedia is a reset, and this reset corresponds to the 'An existing connection was forcibly ...' message I get above.
What really does that mean though? Does this mean that the reset causes the issue? I think the answer to that is no, and what would make more sense is that the reset is a result of the issue? I.e. The socket on the server side 开发者_如何转开发dies for some reason, and the client sends the reset to the server to kind of try and wake it up.
Thoughts?
Sometimes a misbehaving client will get or send what it wants to, then immediately quit (closing the socket, and abruptly severing the connection). It's normal to see that occasionally on any service that's exposed to the internet.
If it's your own code that's causing this, make sure you send any "i'm done now" command (a common one is "QUIT"), and properly "shutdown" the connection before you close it. Aside from that, about the only resets you should be causing would involve your internet access flaking out.
Are both the server and client your own code. Even i have faced similar issue but in my case the server was not my code and so i couldnt really find out why the client was closing the connection and sending PSH and RST messages.
In either case if you get the error like the one you have got it is adivisable to create a new socket and establish communication.
精彩评论