/**************************************************************** ** Copyright 1997 by DTAI Incorporated, All Rights Reserved ** **************************************************************** ** ** $Id: NetServer.java,v 1.1 1999/10/18 17:52:20 csl Exp $ ** ** $Source: /h/chrome/alliance/developer/viewsource/kadel_ssjava/NetServer.java,v $ ** ****************************************************************/ package dtai.net; import java.net.*; import java.io.*; import java.util.*; /** * NetServer - a superclass for a server in a TCP/IP-based client/server * architecture. * * @see dtai.net.NetPortToClient * @version 1.1 * @author DTAI, Incorporated * * $Id: NetServer.java,v 1.1 1999/10/18 17:52:20 csl Exp $ * * $Source: /h/chrome/alliance/developer/viewsource/kadel_ssjava/NetServer.java,v $ */ public abstract class NetServer extends Thread { private int portnum; /** * Opens the given TCP/IP port on the current machine to accept * new clients. Starts a separate thread to execute the server function * of waiting for and accepting the clients. * * @param portnum The specific port number */ public NetServer ( int portnum ) { this.portnum = portnum; start (); } /** * Executes the main body of the thread to loop and wait for and accept * client connections */ public void run () { try { ServerSocket server_socket = null; try { server_socket = new ServerSocket( portnum ); while ( true ) { createClientPort ( server_socket.accept () ); } } catch ( IOException ioerror ) { ioerror.printStackTrace(); } finally { if ( server_socket != null ) { try { server_socket.close(); } catch ( IOException ioe ) { } } } } catch ( Exception e ) { e.printStackTrace(); } } /** * subclass and extend this class to create your own servers * @param socket the socket connection from the client from which * to create the NetPortToClient. * @see NetPortToClient */ protected abstract void createClientPort( Socket socket ); }