tags:

views:

53

answers:

2

Hi All,

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?

A: 

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.

cHao
So the first paragraph you are referring to hackers right? It's not that, but a good point though. You mention sending an 'I'm done now' command. I will look into that because I think that might help. The problem though is that I suspect it is 'not done'. It shouldn't be closing the connection where it is, and if it is I would expect to see some other kind of error.
peter
I'm referring to hackers as well as poorly written (but otherwise legit) clients. As long as your server code can account for people doing stuff "wrong" (legit or not), you don't have much to fear there other than people knowing you have something running on a given port. As for why your client is resetting the connection (and it sounds like that's probably the case, if your internet connection is stable), is it possible that something's triggering an exception, making code leave your using block (you *are* using using blocks, right?) and disposing the socket?
cHao
A: 

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.

ckv