public void addThread(Socket socket) {
   System.out.println("Client accepted: " + socket);
   client = new ChatServerThread(this, socket);
   try {
     client.open();
     client.start();
   } catch (IOException ioe) {
     System.out.println("Error opening thread: " + ioe);
   }
 }
Example #2
0
 public synchronized void remove(int ID) {
   int pos = findClient(ID);
   if (pos >= 0) {
     ChatServerThread toTerminate = clients[pos];
     System.out.println("Removing client thread " + ID + " at " + pos);
     if (pos < clientCount - 1)
       for (int i = pos + 1; i < clientCount; i++) clients[i - 1] = clients[i];
     clientCount--;
     try {
       toTerminate.close();
     } catch (IOException ioe) {
       System.out.println("Error closing thread: " + ioe);
     }
     toTerminate.stop();
   }
 }