squint
Class NetConnection

java.lang.Object
  extended by squint.NetConnection

public class NetConnection
extends java.lang.Object

NetConnection is a class that implements a data connection that supports the transmission of text messages through the Internet to and from a program and a port on a remote computer. It uses the TCP protocol to ensure reliable, ordered delivery of all data.


Field Summary
 SScanner in
          Used to access text received through this connection
 java.io.PrintWriter out
          Used to send text through this connection
 
Constructor Summary
NetConnection(java.lang.String host, int port)
          Constructs a new NetConnection given a the name of a remote host and the port number on that host with which a connection should be made.
NetConnection(java.lang.String host, java.lang.String port)
          Constructs a new NetConnection given a the name of a remote host and the port number on that host with which a connection should be made.
NetConnection(squint.TCPSocket mySocket)
          Constructs a new NetConnection 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 any listener registered for this connectoin.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

public final SScanner in
Used to access text received through this connection


out

public final java.io.PrintWriter out
Used to send text through this connection

Constructor Detail

NetConnection

public NetConnection(java.lang.String host,
                     int port)
Constructs a new NetConnection 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

NetConnection

public NetConnection(java.lang.String host,
                     java.lang.String port)
Constructs a new NetConnection 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

NetConnection

public NetConnection(squint.TCPSocket mySocket)
Constructs a new NetConnection given a Socket already connected to a remote port. This constructor can be used to implement servers based on the NetConnection 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 Socket with which NETConnection 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 NetConnection's state changes

removeMessageListener

public void removeMessageListener()
Remove any listener registered for this connectoin.