import java.net.*;
import java.io.*;
import java.util.*;

public class GenericServer {
// Replace 1234 with the well-known port used by the server.
static int serverPort = 1234;

  public static void main(String args[]){
// Create a server object and run it
    System.out.println("Generic server starting at port " + serverPort );
    GenericServer server = new GenericServer();
    server.run();
  }

  public GenericServer() {
    super();
  }

  public void run() {
    try {
// Create a server socket on the specified port
      ServerSocket server = new ServerSocket(serverPort);
      do {
// Loop to accept incoming connections
        Socket client = server.accept();
// Create a new thread to handle each connection
        (new ServerThread(client)).start();
      } while(true);
    } catch(IOException ex) {
      System.exit(0);
    }
  }
}

class ServerThread extends Thread {
Socket client;
// Store a reference to the socket to which the client is connected

  public ServerThread(Socket client) {
    this.client = client;
  }
// Thread's entry point

  public void run() {
    try {
// Create streams for communicating with client
      ServiceOutputStream outStream = new ServiceOutputStream(
      new BufferedOutputStream(client.getOutputStream()));
      ServiceInputStream inStream =
      new ServiceInputStream(client.getInputStream());
// Read client's request from input stream
      ServiceRequest request = inStream.getRequest();
// Process client's request and send output back to client
      while (processRequest(outStream)) {};
    }catch(IOException ex) {
      System.exit(0);
    }
    try {
      client.close();
    }catch(IOException ex) {
      System.exit(0);
    }
  }
// Stub for request processing

  public boolean processRequest(ServiceOutputStream outStream) {
    return false;
  }
}
// Input stream filter

class ServiceInputStream extends FilterInputStream {


  public ServiceInputStream(InputStream in) {
    super(in);
  }
// Method for reading client requests from input stream

  public ServiceRequest getRequest() throws IOException {
    ServiceRequest request = new ServiceRequest();
    return request;
  }
}
// Output stream filter

class ServiceOutputStream extends FilterOutputStream {
  public ServiceOutputStream(OutputStream out) {
    super(out);
  }
}
// Class to implement client requests

class ServiceRequest {
}