exception - StreamCorruptedException with Android-Java Communication -
i need send serialized data android device java server. don't know why, communication seems unstable. in debugger, java.io.streamcorruptedexception: thrown after start. not 1 object passing. without debugger, 10 messages passed until same exception thrown. got idea, please me:) thank you! fabian
exception:
java.io.streamcorruptedexception: invalid type code: 2f @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.readobject(unknown source) @ androidanbindung.androidverwalter.run(androidverwalter.java:114)
java-code:
public void nachrichtenaustausch(){ port ++; try { serversocket = new java.net.serversocket(port); system.out.println("warte auf 2. verbindungsaufbau..."); client = serversocket.accept(); system.out.println("verbindung 2 ist eingegangen..."); in = new objectinputstream(new objectinputstream(client.getinputstream())); nachricht n; // starte den regulären verkehr mit dem androidgerät new thread(this).start(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } @override public void run() { nachricht speicher; while (true) { try { speicher = (nachricht) in.readobject(); if (speicher != null) { system.out.println(speicher.getname()+"..............................."+speicher.getwerte().get(0)); }synchronized (objekliste) { (androidobject ao : this.objekliste) { if (speicher.getname().equals(ao.name)) { ao.abstrakter_wert = speicher.getaktuellerwert(); if (speicher.getwerte()!=null) { ao.werte = speicher.getwerte(); } } } } thread.sleep(50); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (classnotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); }catch (exception e) { // todo: handle exception } } }
and android thread:
@override public void run() { // todo auto-generated method stub try { while (true) { if (!nachrichtenliste.isempty()) { nachricht speicher = nachrichtenliste.get(0); try { out.writeobject(speicher); out.flush(); synchronized (nachrichtenliste) { nachrichtenliste.remove(speicher); } } catch (ioexception e) { e.printstacktrace(); } } thread.sleep(50); handler.post(this); } } catch (exception e) { // todo: handle exception } }
i can imagine android , java not serialization compatible here. 1 side sends code other not expect.
i'd rather go more textual protocol (json, xml) here, serialization.
Comments
Post a Comment