so here is the deal: I have a server running that is constantly accepting clients by TCP socket:
public ArrayList<Socket> lista_users = new ArrayList<Socket>();
Socket s;
s = serverSocket.accept();
lista_users.add(s);
avisa_all(lista_users, s);
Thread t_trata_cliente = new Thread(new trata_cliente(lista_users, s));
t_trata_cliente.start(); //this Thread is responsable for interacting with
//the clients (where my question is)
Saving the sockets on array list. After i want to send different type of information to my clients(Thread "trata_cliente"). When i say different type of information i mean, first send a warning message, then an object, then some message, then object again.
What is the best way to do it?
Encapsulate the output stream of the socket with the appropriate wrapper:
DataOutputStream
: To send primitive data type + Strings. ObjectOutputStream
: To send objects through the stream.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.