squint
Class TCPConnection

java.lang.Object
  extended by squint.TCPConnection

public class TCPConnection
extends java.lang.Object

A 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.
 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