java - send arraylist through the socket -
this question has answer here:
i have socket (the server , client side). in server side have arraylist . each time new user connect, add arraylist. send arraylist . when client receives arraylist:
first client [user1] second client [user1,user2] third client [user1,user2,user3]
but if send string , receives correctly.
i used objectinputstream , objectoutputstream
//server side public void telleveryone(){ iterator = clientoutputstreams.iterator(); while(it.hasnext()){ try{ objectoutputstream oos = (objectoutputstream) it.next(); oos.writeobject(namesmachines); }catch(exception ex){} } } //client side public void run(){ object obj; try{ while((obj=ois.readobject())!=null){ castobject(obj); } }catch(exception ex){} }
you need use objectoutputstream.writeunshared()
, or call objectoutputstream.reset()
. otherwise objects have been transmitted not retransmitted.
Comments
Post a Comment