package clientserver; import java.io.*; import java.net.*; public class Server extends Thread { ServerBehavior behavior; ServerSocket ss; public Server(ServerBehavior behavior, int port) throws IOException { this.behavior = behavior; ss = new ServerSocket(port); } public void run() { try { while (true) { (new ClientHandler(ss.accept(), behavior)).start(); } } catch (IOException ioe) { // an exception here indicates a failure of the server socket try { ss.close(); } catch (IOException closeFailure) { } ioe.printStackTrace(); } } }