문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top