Fundamentals of iostream and read/writeObject calls Fundamentals of iostream and read/writeObject calls android android

Fundamentals of iostream and read/writeObject calls


Not sure if this causes this specific problem, but you should always use this order when creating object streams:

  1. Create ObjectOutputStream
  2. Flush it
  3. Create ObjectInputStream

I see that at least on the server side you created ObjectInputStream first and didn't flush the stream which might cause your problems.

Here is more info about the topic and reasons behind this order.


You should choose a server port above 1024, as all the ports below are reserved for known services. Just choose a port between 1024 and 65535 and see if it works then.

Also I would advise you to wrap your ObjectInputStream into a BufferedInputStream; It may be that once your connection isn't that steady, it will fail.


I think this is because, your client exits after executing

objectOutputStream.writeObject(message) ;

So try to introduce artificial delay after this line and see.

In all the cases, when client/server closes the connections/terminates the program, then the other end will throw this EOF exception if it is waiting for any input(eg, inputObjectStream.readObject())

so make sure that whatever is written by client is properly read by the server before the client terminates. So introduce some delay at the client and see.