I’m using a ServerSocket and ObjectOuputStream in Java to transfer some objects for a project of mine from a client to a server. I understand that the ServerSocket class in Java uses TCP and so no packets should be dropped, but what happens if the client crashes in the middle of streaming an object? Do I need to be handling this myself, or will Java recognize that the object coming through the stream is incomplete?
I’m using a ServerSocket and ObjectOuputStream in Java to transfer some objects for a
Share
Depending on way the connection is severed, you could get one of several exceptions on the server. Your server may complain with an exception such as
Connection reset by peer. Yes your container can recognize that the connection did not terminate correctly. The exception thrown by your container will indicate this.Note that there are cases where the client may fully transfer your object but the server may still not get it. A load balancer sitting between the two can sever the connection for unknown reasons. Consider those cases too.