Remember that your server is blocked, and waiting, for client joke/proverb input.
But, you also want it blocked, and waiting, for administration input.
It is not possible to block a single thread in two places at once. Thus, it is a certainty that you will have to make an asynchronous call to start a blocking wait for adminstration input, before sending on the main program thread into the blocking wait for client input.
Something like the following code will do this:
public static void main(String a[]) throws IOException {
int q_len = 6; /* Number of requests for OpSys to queue */
int port = 4545;
Socket sock;
AdminLooper AL = new AdminLooper(); // create a DIFFERENT thread
Thread t = new Thread(AL);
t.start(); // ...and start it, waiting for administration input
ServerSocket servsock = new ServerSocket(port, q_len);
System.out.println("Clark Elliott's Joke server starting up at port 4545.\n");
while (controlSwitch) {
// wait for the next client connection:
sock = servsock.accept();
new Worker (sock).start();
}
}
and
class AdminLooper implements Runnable {
public static boolean adminControlSwitch = true;
public void run(){ // RUNning the Admin listen loop
System.out.println("In the admin looper thread");
int q_len = 6; /* Number of requests for OpSys to queue */
int port = 5050; // We are listening at a different port for Admin clients
Socket sock;
try{
ServerSocket servsock = new ServerSocket(port, q_len);
while (adminControlSwitch) {
// wait for the next ADMIN client connection:
sock = servsock.accept();
new AdminWorker (sock).start();
}
}catch (IOException ioe) {System.out.println(ioe);}
}