squint
Class TCPPort

java.lang.Object
  extended by squint.TCPPort

public class TCPPort
extends java.lang.Object

A TCPPort is a class that provides access to a port through which connections can be made to a program acting as a server.


Constructor Summary
TCPPort(int portNum)
          Create a new TCPPort.
 
Method Summary
 NetConnection acceptNetConnection()
          Await a connection from a client.
 TCPConnection acceptTCPConnection()
          Await a connection from a client.
 void addConnectionListener(ConnectionListener whoCares)
          Add a connection listener to this TCPPort.
 void close()
          Close the port
 int getLocalPort()
          Determine the port number associated with this port
 java.lang.String toString()
          Return a string description of the port
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TCPPort

public TCPPort(int portNum)
Create a new TCPPort. Throws an execption if the port is not available

Parameters:
portNum - the desired port number (a random free port will be assigned if the parameters value is 0)
Method Detail

close

public void close()
Close the port


getLocalPort

public int getLocalPort()
Determine the port number associated with this port

Returns:
the port number

addConnectionListener

public void addConnectionListener(ConnectionListener whoCares)
Add a connection listener to this TCPPort. Only one listener can be associated with a port at a time.

Parameters:
whoCares - the object that should be notified when a connection is established

acceptTCPConnection

public TCPConnection acceptTCPConnection()
Await a connection from a client. When a client finally makes a connection, return a TCPConnection object through which the client can send data to this program

Returns:
the new connection

acceptNetConnection

public NetConnection acceptNetConnection()
Await a connection from a client. When a client finally makes a connection, return a NetConnection object through which the client can send data to this program

Returns:
the new connection

toString

public java.lang.String toString()
Return a string description of the port

Overrides:
toString in class java.lang.Object
Returns:
the description of the port