First, Below codes are simple
Java socket programming,
==== Server Codes =====
I think the above server application codes work well, It throws no exceptions. But the problem is that the below client socket codes throws "Socket closed Exception" when the client stops.
==== Client Codes ======
The exception is
java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at com.aaa.client.InputThread.run(JavaChatClient.java:66)
It seems when the "br.readLine()" line is executed, the the socket of BufferedReader objects br is already closed. So it throws Socket closed Exception.
I'd like to know how to close the BufferedReader br object automatically when the client socket connection is disconnected.
I am totally stuck here. Any advice will be appreciated. Thanks