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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -