'Connection reset' usually means you have written to a connection that had already been closed by the peer. In other words, an application protocol error. You've written something that the peer didn't read. The next I/O operation, or a subsequent one depending on buffering, will get 'connection reset'.
In this case the server is writing totalCharge
and initializing two ObjectOutputStreams
, which both write headers to the stream. The client is only creating one ObjectInputStream,
which reads one header, and reads one object, then closes the connection. So the other header is written nowhere and causes the exception.
You can't do this. You can't use multiple ObjectOutputStreams
on the same socket, at least not without special care that isn't evident here. You also shouldn't be doing any I/O whatsoever in the accept loop. Move all the client processing to the HandleAClient class, which is what it's for after all, and don't do anything in the accept loop except accept connections and start threads for them.
Also neither your server nor your client is closing the connection. The server is just leaking sockets, and the client is just exiting. The operating system is closing it for you in the client case, but it's poor practice. Close your connections. In this case you should close the ObjectOutputStream.