Skip to content
Advertisement

Java, server client TCP communication ends with RST

I’m trying to figure out if this is normal. Because without errors, a connection should be terminated by:

JavaScript

I get this at the end of a TCP connection (over SSL, but i also get it with non-encrypted):

JavaScript

The client exits normally and reaches socket.close, shouldn’t then the connection be shut down normally, without a reset?

I can’t find anything about the TCP streams of java on google…

Here is my code:

Server:

JavaScript

Client:

JavaScript

Thanks a lot, on a non-SSL connection, I now get a nice orderly connection shutdown without a reset.

BUT apparently this method is not supported by SSLSocket? When I try it in my SSL client, I get the following exception:

JavaScript

My new code looks like this:

JavaScript

Am I not using it correcty? Or is my SSLSocket not correct? Because with a non-SSL connection there is no problem.

Advertisement

Answer

Your packet log shows that the client is sending its last bit of data, and notifying the server of the connection closing.

The server then sends back its last bit of data (the last converted integer, presumably). The client responds with a RST, which indicates that the client socket was closed for both reading and writing – the client is saying “sorry, I didn’t catch that last bit of data, I’m not listening anymore”.

I am not a Java guru, but it appears that calling the .close() method of the socket’s OutputStream is resulting in the .close() method being called on the socket itself. What you actually want to happen here (after the client has written its last integer) is that the shutdownOutput() method is called on the socket.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement