squint
Class TCPConnection

java.lang.Object
  extended by squint.TCPConnection
Direct Known Subclasses:
SecureTCPConnection

public class TCPConnection
extends java.lang.Object

TCPConnection is a class that implements a data connection that supports the transmission of binary and text data through the Internet to and from a program and a port on a remote computer.


Field Summary
 DataInputChannel in
          Used to access data received through this connection
 DataOutputChannel out
          Used to send data through this connection
 
Constructor Summary
TCPConnection(java.net.Socket aSocket)
          Constructs a new TCPConnection given a Socket already connected to a remote port.
TCPConnection(java.lang.String host, int port)
          Constructs a new TCPConnection given a the name of a remote host and the port number on that host with which a connection should be made.
TCPConnection(java.lang.String host, java.lang.String port)
          Constructs a new TCPConnection given a the name of a remote host and the port number on that host with which a connection should be made.
TCPConnection(squint.TCPSocket mySocket)
          Constructs a new TCPConnection given a Socket already connected to a remote port.
 
Method Summary
 void addMessageListener(TCPListener listener)
          Register to be notified when new data is received through this connection and when the connection is terminated.
 void close()
          Terminate the connection to the remote machine.
 java.lang.String getLocalAddress()
          Returns the Internet address of this machine used for this connection
 int getLocalPort()
          Returns the port number associated with the other end of this connection
 java.lang.String getRemoteAddress()
          Returns the Internet address of the machine at the other end of this connection
 int getRemotePort()
          Returns the port number associated with the other end of this connection
 void removeMessageListener()
          Remove the listener registered for this connection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

public final DataInputChannel in
Used to access data received through this connection


out

public final DataOutputChannel out
Used to send data through this connection

Constructor Detail

TCPConnection

public TCPConnection(java.lang.String host,
                     int port)
Constructs a new TCPConnection given a the name of a remote host and the port number on that host with which a connection should be made.

Parameters:
host - the name of the remote host
port - the number of the port to contact

TCPConnection

public TCPConnection(java.lang.String host,
                     java.lang.String port)
Constructs a new TCPConnection given a the name of a remote host and the port number on that host with which a connection should be made.

Parameters:
host - the name of the remote host
port - the number of the port to contact (in String form)

TCPConnection

public TCPConnection(squint.TCPSocket mySocket)
Constructs a new TCPConnection given a Socket already connected to a remote port. This constructor can be used to implement servers based on the TCPConnection class. In this case, the Socket passed to this constructor would be obtained as the result of invoking the accept method of a ServerSocket.

Parameters:
mySocket - the TCPSocket with which TCPConnection should be associated

TCPConnection

public TCPConnection(java.net.Socket aSocket)
Constructs a new TCPConnection given a Socket already connected to a remote port. This constructor can be used to implement servers based on the TCPConnection class. In this case, the Socket passed to this constructor would be obtained as the result of invoking the accept method of a ServerSocket.

Parameters:
aSocket - the Socket with which TCPConnection should be associated
Method Detail

close

public void close()
Terminate the connection to the remote machine.


addMessageListener

public void addMessageListener(TCPListener listener)
Register to be notified when new data is received through this connection and when the connection is terminated.

Parameters:
listener - the object whose dataReceived and connectionClosed methods should be invoked when the TCPConnection's state changes

removeMessageListener

public void removeMessageListener()
Remove the listener registered for this connection


getRemoteAddress

public java.lang.String getRemoteAddress()
Returns the Internet address of the machine at the other end of this connection

Returns:
the IP address of the machine at the other end of this connection in the form ddd.ddd.ddd.ddd

getRemotePort

public int getRemotePort()
Returns the port number associated with the other end of this connection

Returns:
the port number used at the other end of this connection

getLocalAddress

public java.lang.String getLocalAddress()
Returns the Internet address of this machine used for this connection

Returns:
the IP address of this machine used for this connection in the form ddd.ddd.ddd.ddd

getLocalPort

public int getLocalPort()
Returns the port number associated with the other end of this connection

Returns:
the port number used at the other end of this connection