Question

I am stuck with this very strange problem. In the client I am passing in objects like

try{
    oos.writeObject(new GameStartSerializedObject());
    oos.flush();
}
catch(Exception e){
    e.printStackTrace();
}

and in the server I am reading the object

try{
    //Its my turn
    thrown_message = player_reader.readObject();
}
catch(Exception e){

My question is why am i getting EOF exception. My understanding of object input stream is when i call readObject() i should block until i get an object so how does it know if the eof is reached? Please help!

This is how I create object streams

ois = new ObjectInputStream(socket.getInputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
oos.flush();

Also, after i write object and flush should i close the stream. I am not closing it since the objects are written pretty regularly from different parts of the code one after another.

Était-ce utile?

La solution

The peer has closed the connection. Ergo there are no more objects to read. Ergo you have reached the end of the stream. Ergo readObject() throws EOFException.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top