2

所以这是交易:我有一个正在运行的服务器,它不断地通过 TCP 套接字接受客户端:

public ArrayList<Socket> lista_users = new ArrayList<Socket>();

插座;

            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)

将套接字保存在数组列表中。在我想向我的客户发送不同类型的信息之后(线程“trata_cliente”)。当我说不同类型的信息时,我的意思是,首先发送警告消息,然后发送对象,然后发送一些消息,然后再次发送对象。

最好的方法是什么?

4

1 回答 1

4

用适当的包装器封装套接字的输出流:

于 2012-11-27T02:45:28.637 回答