Hi i am building a little p2p program, implementing both the server-side and the client-side. when I lunch the client-side program, first think it does is to connect to each server in its list, send data (about the client-side) and disconnect. The next time the client-side connects to one of these servers it will be recognized.
My problem - when i tell the client-side to disconnect, i get this exception
java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at oop.ex3.nameserver.NameServerThread.run(NameServerThread.java:24)
to disconnect i just wrote:
finally {
out.close();
in.close();
socket.close();
}
so, how do i avoid this exception? thanks!
The JavaDoc for Socket.close() states clearly:
Closing this socket will also close the socket's InputStream and OutputStream.
which will throw the exception since you've already closed them!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With