Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic class NetDrawServer { private List actions; ... public NetDrawServer(int port) { this.port = port; actions = new Vector(); } ... public void launch() { ... while (running) { try { Socket socket = serverSocket.accept(); ClientHandler handler = new ClientHandler(socket, clientList, actions); handler.start(); } catch (IOException e) { System.out.println("Somebody jibbled up their connection when connecting."); } catch (Exception e) { System.out.println("Somebody tried to join the server in a jibbly way."); } } ... }
public class ClientHandler extends Thread { private List actions; ... public ClientHandler(Socket socket, ClientList clientList, List actions) { this.socket = socket; this.clientList = clientList; this.actions = actions; } .... public void run() { ... if (tokens[0].equals("join")) { name = tokens[1]; ClientOutputThread clientOutputThread = new ClientOutputThread(clientList, firstLine); clientOutputThread.start(); //Envoie de la liste des actions effectuées précédemment bwriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); Iterator iterator = actions.iterator(); while (iterator.hasNext()) { writeLine((String) iterator.next()); } } else { socket.close(); return; } ...} ... public synchronized void addAction(String action) { actions.add(action); } }
public class ClientInputThread extends Thread { ... public void run() { ... clientHandler.addAction(line); ClientOutputThread clientOutputThread = new ClientOutputThread(clientList, line); clientOutputThread.start(); ... } }