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.
来源:https://stackoverflow.com/questions/20913190/why-is-objectinputstream-readobject-throwing-eof-exception