java - StreamCorruptedException: invalid type code: AC -


my problem when tries read object second time, throws exception:

java.io.streamcorruptedexception: invalid type code: ac     @ java.io.objectinputstream.readobject0(objectinputstream.java:1356)     @ java.io.objectinputstream.readobject(objectinputstream.java:351)     @ client.run(basestainstance.java:313)  java.io.streamcorruptedexception: invalid type code: ac     @ java.io.objectinputstream.readobject0(objectinputstream.java:1356)     @ java.io.objectinputstream.readobject(objectinputstream.java:351)     @ client.run(basestainstance.java:313) 

the first time send exact same object message; however, when try doing same thing second time, throws error above. need re-intialize readobject() method? printed out message object being received line below , exact same first instance works ok.

object buf = myinput.readobject(); 

i'm assuming there's problem appending, have no use appending. want read fresh line everytime. i'd appreciate in fixing bug. thank you.

==================================

before 1 line, i'm creating input , output objects socket in run() method. object declaration outside run() method in class:-

@override public void run() {     try {         sleep((int) 1 * 8000);     } catch (exception e) {         e.printstacktrace();     }      try {         //creating input , output streams transfer messages server         myoutput = new objectoutputstream(skt.getoutputstream());         myinput = new objectinputstream(skt.getinputstream());         while (true) {             buf = myinput.readobject();         }     } catch (unknownhostexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } {         try {         } catch (exception e) {             e.printstacktrace();         }     } } 

you're right; don't close object. i'm not sure how that.

the underlying problem using new objectoutputstream write existing objectinputstream have used prior objectoutputstream write to. these streams have headers written , read respective constructors, if create objectoutputstream write new header, starts - guess what? - 0xac, , existing objectinputstream isn't expecting header @ point barfs.

in java forums thread cited @trashgod, should have left out part 'anew each object @ both ends': that's wasteful. use single oos , ois life of socket, , don't use other streams on socket.

if want forget you've written, use objectoutputstream.reset().

and don't use other streams or readers or writers on same socket. object stream apis can handle java primitive datatypes , serializable classes.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -