java - EOFException in objectinputstream readobject -


i want make server client application. set , error. want app wait till more data.

java.io.eofexception @ java.io.objectinputstream$blockdatainputstream.peekbyte(unknown source) @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.readobject(unknown source) 

on line:

listener.received(inputstream.readobject(), id.id); 

server code:

isrunning = true;     thread input = new thread(new runnable(){         @override         public void run() {             try{                 serversocket server = new serversocket(localport);                 while(isrunning){                     socket socket = server.accept();                     objectoutputstream outputstream = new objectoutputstream(socket.getoutputstream());                     objectinputstream inputstream = new objectinputstream(socket.getinputstream());                     object obj = inputstream.readobject();                     if(obj instanceof id){                         id id = (id) obj;                         if(connctedchecker(id.id)){                             id myid = new id(id, localip, localport);                             outputstream.writeobject(myid);                             connect(id.ip, id.port);                             listener.connected(id.id);                             do{                                 listener.received(inputstream.readobject(), id.id);                             }while(socket.isconnected());                             listener.disconnected(id.id);                             closeconnection(id.id);                         }                     }                     inputstream.close();                     outputstream.close();                     socket.close();                 }                 server.close();             }catch(exception e){                 e.printstacktrace();             }          }     });     input.start(); 

client code:

output = new thread(new runnable(){         @override         public void run(){             try {                 socket = new socket(remoteip, remoteport);                 inputstream = new objectinputstream(socket.getinputstream());                 outputstream = new objectoutputstream(socket.getoutputstream());                 id id = new id(id, localip, localport);                 outputstream.writeobject(id);                 outputstream.flush();                 object obj = inputstream.readobject();                 if(obj instanceof id){                     id inid = (id) obj;                     remoteid = inid.id;                 }                 while(socket.isconnected()){                     object object = queue.take();                     outputstream.writeobject(object);                     outputstream.flush();                 }             } catch (exception e) {                 e.printstacktrace();             }         } 

the listener:

public class listener {  public void connected(uuid id){  }  public void received(object object, uuid id){  }  public void disconnected(uuid id){  }  } 

                        do{                             listener.received(inputstream.readobject(), id.id);                         }while(socket.isconnected()); 

unless socket/inputstream has infinite number of objects send, going run out of objects sooner or later. that's has happened. says right in javadoc eofexception.

signals end of file or end of stream has been reached unexpectedly during input.

this exception used data input streams signal end of stream. note many other input operations return special value on end of stream rather throwing exception.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -