java - ObjectInputStream not working -


so have program thats connect main server i'm asking main server open new server(lets call small server) , connect him far :)

then i'm sending small server string,int , object using line of code:

objectoutputstream  toserver = new objectoutputstream(socket.getoutputstream()); 

again far :)

the problem starts when want read small server client using line of code:

objectinputstream fromserver = new objectinputstream(socket.getinputstream()); 

my problem client doesn't data small server(bool , int)..

i'm getting error:

java.io.eofexception     @ java.io.objectinputstream$blockdatainputstream.readboolean(objectinputstream.java:2737)     @ java.io.objectinputstream.readboolean(objectinputstream.java:884)     @ addemployee.addemployee(addemployee.java:168)     @ addemployee.access$5(addemployee.java:136)     @ addemployee$1.run(addemployee.java:110)     @ java.awt.event.invocationevent.dispatch(invocationevent.java:209)     @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:715)     @ java.awt.eventqueue.access$400(eventqueue.java:82)     @ java.awt.eventqueue$2.run(eventqueue.java:676)     @ java.awt.eventqueue$2.run(eventqueue.java:674)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.accesscontrolcontext$1.dointersectionprivilege(accesscontrolcontext.java:86)     @ java.awt.eventqueue.dispatchevent(eventqueue.java:685)     @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:296)     @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:211)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:201)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:196)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:188)     @ java.awt.eventdispatchthread.run(eventdispatchthread.java:122) 

yea pretty ha ha :)

here client code:

*global.toserver , global.fromserver connectors main server!!!

try         {             int port;             global.toserver.writeint(btnaddemp.gettag());             global.toserver.flush();             try{              port=global.fromserver.readint();              try {                     thread.sleep(100);                 } catch (interruptedexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }              socket socket= new socket("localhost",port );              objectoutputstream toserver = new objectoutputstream(socket.getoutputstream());             toserver.flush();             objectinputstream fromserver = new objectinputstream(socket.getinputstream());             toserver.writeint(2);             toserver.flush();             toserver.writeutf(passwordgenereator());             toserver.flush();             toserver.writeint(global.idcompany);             toserver.flush();             toserver.writeobject(newemp);             toserver.flush();             system.out.println(fromserver.available());//idk if part of problem give me 0                 if(fromserver.readboolean())                 {                     //toserver.flush();                     int num=fromserver.readint();                     system.out.println(num);                 }              socket.close();         }          catch (unknownhostexception e1) {             // todo auto-generated catch block             e1.printstacktrace();         } catch (ioexception e2) {             // todo auto-generated catch block             e2.printstacktrace();         }             }catch(ioexception e3)             {                 e3.printstacktrace();             } 

and small server code:

if(whattodo==2)              {                  try {                     string pass=inputfromclient.readutf();                     int idcomp=inputfromclient.readint();                     employee newemp=(employee)inputfromclient.readobject();                     system.out.println(string.format("insert `employees`(`empnumber`, `fname`, `lname`, `birthdate`, `address`, `email`, `password`, `idcompany`) values ('%d','%s','%s','%s','%s','%s','%s','%d')",newemp.getempnumber(),newemp.getfname(),newemp.getlname(),newemp.getbirthdate(),newemp.getaddress(),newemp.getemail().getemailaddress(),pass,idcomp));                       statement=con.preparestatement(string.format("insert `employees`(`empnumber`, `fname`, `lname`, `birthdate`, `address`, `email`, `password`, `idcompany`) values ('%d','%s','%s','%s','%s','%s','%s','%d')",newemp.getempnumber(),newemp.getfname(),newemp.getlname(),newemp.getbirthdate(),newemp.getaddress(),newemp.getemail().getemailaddress(),pass,idcomp));                       int result1=statement.executeupdate();                       system.out.println(result1);                       if(result1==1)                       {                           system.out.println("poooo");                             outputtoclient.writeboolean(true);                           statement=con.preparestatement(string.format("select idemp employees empnumber=%d",newemp.getempnumber()));                             result=statement.executequery();                             if(result.next())                             {                                 system.out.println(result.getint(1));                                 int send=result.getint(1);                                 system.out.println(send);                                 outputtoclient.writeint(send);                             }                       }                 } catch (classnotfoundexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 } 

what should do?? thank helpers :)

ok manage solved after 4 hours small line after every sending in small server side:

outputtoclient.flush(); 

this means there's nothing read. error says.

you should make sure have data written out before trying read.

you have many conditions before writing out something. check what
these conditions evaluate, maybe don't point of writing.

"objectinputstream not working" pretty strong statement,
program using objectinputstream not working.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -