iglu.net
Class PortServer

java.lang.Object
  |
  +--iglu.net.PortServer

public class PortServer
extends java.lang.Object

The PortServer creates a socket which listens on the port specified in the constructor. When a client connects, it creates a new socket on another port for communication with the client. Then is creates and starts a ClienHandler thread to deal with the client. It continues until keepGoing is set to false. See iglu.examples.PortServerExample.java for a simple example.

Since:
February 2000
Version:
0.1
Author:
Travis Bauer trbauer@indiana.edu
See Also:
ProxyServerExample

Field Summary
protected  java.net.InetAddress addr
          Which host the port server is running on
(package private)  ClientCreator clientCreator
          the object that knows how to create the client threads to handle the clients.
protected  boolean keepGoing
          Whether or not to keep looking for more clients.
protected  java.lang.Integer port
          Which port the server is running on
(package private)  java.net.ServerSocket serverSocket
          the server which watches the port listening for new clients
 
Constructor Summary
PortServer(java.net.InetAddress addr, java.lang.Integer port, ClientCreator ncc)
          this constructor opens and listens on the indicated port at the indicated address.
 
Method Summary
 void clientDone(ClientHandler nc)
          Post-processing of the clientHandler.
protected  void clientReady(ClientHandler nc)
          Pre-processing of the clientHandler.
 java.net.InetAddress getHost()
          Which host the port server is running on
 java.lang.Integer getPort()
          Which port the server is running on
 ClientHandler getWatcher(java.net.Socket client, PortServer ms)
          This returns a ClientHandler which handles the input from the client.
 void go()
          Starts watching the socket.
 void stop()
          quit looking for clients
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keepGoing

protected boolean keepGoing
Whether or not to keep looking for more clients. Set this to false to stop the server.


serverSocket

java.net.ServerSocket serverSocket
the server which watches the port listening for new clients


clientCreator

ClientCreator clientCreator
the object that knows how to create the client threads to handle the clients. This is designed to work after the fashion of actionListener in JButton


port

protected java.lang.Integer port
Which port the server is running on


addr

protected java.net.InetAddress addr
Which host the port server is running on

Constructor Detail

PortServer

public PortServer(java.net.InetAddress addr,
                  java.lang.Integer port,
                  ClientCreator ncc)
this constructor opens and listens on the indicated port at the indicated address. When it receives a new connection is will call ClientCreator's createClient routine to create a thread to handle the new connection.

Parameters:
addr - The internet address of the machine containing the server.
port - The port to listen on.
ncc - The ClientCreator.
Method Detail

go

public void go()
Starts watching the socket. Note: If you want the server to run on its own thread, use PortServerThread.


clientReady

protected void clientReady(ClientHandler nc)
Pre-processing of the clientHandler. The client has been created and will start working after this function call

Parameters:
nc - The clientHandler being pre-processed

clientDone

public void clientDone(ClientHandler nc)
Post-processing of the clientHandler. The client is done and the server can do something with it before it is destroyed

Parameters:
nc - The ClientHandler being wrapped up.

getWatcher

public ClientHandler getWatcher(java.net.Socket client,
                                PortServer ms)
                         throws java.io.IOException
This returns a ClientHandler which handles the input from the client. by default, it returns an object of type ClientHandler. It creates a clientHandler as specified in the constructor.

Parameters:
client -
ms -
Throws:
java.io.IOException

getHost

public java.net.InetAddress getHost()
Which host the port server is running on


getPort

public java.lang.Integer getPort()
Which port the server is running on


stop

public void stop()
quit looking for clients