EOFException
during readUTF()
just means it's reached the end of the stream, like it says on the tin. Note that this method doesn't return null
at end of stream, unlike readLine()
(but like all other readXXX()
methods).
It can also mean that your sending and receiving is out of sync, e.g. you are trying to read some ridiculously large number of bytes because you left out a readInt()
or similar, or you wrote something extra at the peer that you shouldn't have, so you're trying to read the next bytes in the stream as the result of writeUTF()
when it isn't. This is an application protocol error.
How this happened in the code you posted is another question, but your code doesn't close the sockets, which doesn't help. Add an out.close()
to your server code, and in.close()
to the client code. However I cannot reproduce your problem with or without these closes. Are you sure this is the real code?