EOFException in objectinputstream readobject

前端 未结 2 1985
不思量自难忘°
不思量自难忘° 2021-01-28 08:53

i want to make a server client application. i set everything up and i get this error. i want the app to wait till i get more data.

java.io.EOFException
at java.         


        
相关标签:
2条回答
  • 2021-01-28 09:25

    Are all your Objects used in WorkerMessageToMaster serializable, as well as WorkerMessageToMaster itself? Every Object you want to send with ObjectStreams have to implement serializable, and all children of it have to have it implemented. String, as well as primitive datatypes (int, float etc) are serializable without you needing to do anything. But if you use your own classes, they have to implement serializable.

    0 讨论(0)
  • 2021-01-28 09:43
    do{
        listener.Received(inputstream.readObject(), id.ID);
    } while(socket.isConnected());
    

    Unless your socket/inputstream has an infinite number of objects to send, it is going to run out of objects sooner or later. That's what has happened. It says so right in the javadoc for EOFException.

    Signals that an end of file or end of stream has been reached unexpectedly during input.

    This exception is mainly used by data input streams to signal end of stream. Note that many other input operations return a special value on end of stream rather than throwing an exception.

    0 讨论(0)
提交回复
热议问题