Forgive me if this is simple, as I’m fairly new to server/client coding and am trying to teach myself.
I’ve made a server and client which work fine and interact perfectly while both are running. The problems I run in to are when I exit the application that contains the client. As soon as I do, I get an unending error saying:
null -- Connection reset
java.net.SocketInputStream.read(SocketInputStream.java:113)
java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
java.io.BufferedInputStream.read(BufferedInputStream.java:317)
sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:107)
sun.nio.cs.StreamDecoder.read(StreamDecoder.java:93)
java.io.InputStreamReader.read(InputStreamReader.java:151)
Calling the close() method on the client’s reference to the socket doesn’t seem to have any effect on this whatsoever. I tried calling if(socket.isClosed()) from the server, but it says it’s still open even after the client has closed it.
How can I handle closing streams and sockets gracefully when my application exits?
If at all possible, you can send some command that will tell your server application to close the connection.