exception - How to send serialized data over a TCP connection in java -
i want send data have serialized on tcp connection. have created client/server connection , sending object after serializing it. however, dont know how should read data.
here code snippet:
sending function:
sendto(string receiveraddr, int receiverport,....., object data) { . . . if (data != null) { byte[] byteobj = programming5.io.serializer.serializebytes(data); output.writeint(byteobj.length); output.write(byteobj, 0, byteobj.length); output.flush(); } output.close(); sock.close(); }
function call:
string hostname = somevalue; int portno = somevalue; hashtable <integer, integer> object = somevalue; sendto(hostname,portno,...,object);
receiving function:
datainputstream input = new datainputstream(clientsocket.getinputstream()); int length = input.readint(); byte[] bytes = new byte[length]; input.readfully(bytes); hashtable<integer, integer> recvobj = (hashtable<integer,integer)programming5.io.serializer.deserialize(bytes);
this not working. getting following exception:
invalid stream header: 07f8aced java.io.streamcorruptedexception: invalid stream header: 07f8aced
please tell me how should go this.
use objectoutputstream
write objects , objectinputstream
read them.
Comments
Post a Comment