package mug13; /* * MainServerThread accepts incoming clients and keeps track * of all the connected clients * * @author Brett McMillian * @author Louisa Poythress * */ import java.net.*; import java.io.*; import java.util.*; public class MainServerThread extends Thread { //*************** // Fields //*************** Socket clientSocket = null; ServerSocket serverSocket; //clients is a hashtable of key/value pairs where //the keys are strings of client usernames, //and the values are the clients' corresponding //ObjectOutputStreams public Hashtable clients = new Hashtable(20,10); //*************** // Constructors //*************** public MainServerThread(ServerSocket ss) { this.serverSocket = ss; } //*************** // Methods //*************** public void run() { try { while (true) { //Accept an incoming client connection clientSocket = this.serverSocket.accept(); //Start a thread on the new client ServerThread newThread = new ServerThread(this.clientSocket, this); newThread.start(); //Wait for the user to login, then add them to the //hashtable synchronized (newThread) { while (!(newThread.clientLogin)) { try { newThread.wait(); } catch (InterruptedException e) {} } clients.put(newThread.getName(), newThread.oosFromServer); } } } catch (IOException e) {System.out.println("I/O Error");} } }