import java.net.*; import java.io.*; import java.lang.*; public class Server { public static int threads = 0; public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(5421); } catch (IOException e) { System.err.println("Could not listen on port: 5421."); System.exit(-1); } while (true) { System.out.println("Listening for Clients...."); new ServerThread(serverSocket.accept()).start(); // if gets aproached by client sets up new thread to deal ++threads; // increments non of threads by 1 System.out.println("Client thread initiated - thread count = " + threads); } } }