/* MultiHosts.java ---------------------------------------------------- Version 1.0 Example of how to get a string argument, and spawn a listener at that port. C. Elliott 2010-03-12 -------------------------------------------------------------------------*/ import java.io.*; // Get the Input Output libraries import java.net.*; // Get the Java networking libraries class NullWorker extends Thread { // Class definition Socket sock; // Class member, socket, local to worker NullWorker (Socket s) {sock = s;} // Constructor, assign arg s to local sock public void run(){ System.out.println("How did you ever get here? Kill me!\n"); } } public class MultiHosts { public static boolean controlSwitch = true; public static void main(String a[]) throws IOException { int q_len = 6; /* Number of requests for OpSys to queue */ int port = 45050; /* Default port value */ if (a.length == 1) try { // Have an argument, so use it port = Integer.parseInt(a[0]); } catch(NumberFormatException Ex) { /* Have checked that a[0] is actually a number */ System.out.println(a[0] + " is not an Integer"); System.exit(5); } Socket sock; ServerSocket servsock = new ServerSocket(port, q_len); System.out.println("Elliott's NullServer running at " + port + "\n"); System.out.println("I do nothing, kill me now!\n"); while (controlSwitch) { // wait for the next client connection: sock = servsock.accept(); new NullWorker (sock).start(); } } }