com.msi.network.connection
Interface Connection

All Known Implementing Classes:
TCPConnection

public interface Connection

Defines the methods necessary to communicate over the ServiceInterface with the client. Connections persist only so long as the client or the server maintains them. When either side closes the connection it will be dropped on the other end.

Version:
1.0
Author:
thompson@milestonesolutions.com

Method Summary
 void close()
          Shut down cleanly.
 java.net.InetAddress getClientAddress()
          Provide the client internet address.
 int getClientPort()
          Provide the client port.
 java.lang.String getLine()
          Reads from the low level communications channel.
 java.lang.String getLine(long TO)
          Reads from the low level communications channel timing out after the specified time.
 int getServerPort()
          Provide the server port often used as ID.
 void init()
          Make sure everything is set up and ready to run.
 void putLine(java.lang.String ln)
          Sends a single line back to the client.
 void putLine(java.lang.String ln, java.net.InetAddress cAddress, int cPort)
          Sends a single line back to the client.
 int read(byte[] data)
          Read an array-full of data.
 int read(byte[] data, long TO)
          Read an array-full of data timing out in the specified period.
 void reset()
          Flush, close and re-init.
 

Method Detail

getLine

public java.lang.String getLine()
                         throws ConnectionException
Reads from the low level communications channel. This is provided for protocols and commands that may need multiple lines and it may not be used in cases (datagram) that are not connection-oriented.

Returns:
String sent from the client with EOL stripped.
Throws:
ConnectionException - if an error occurs

getLine

public java.lang.String getLine(long TO)
                         throws ConnectionException
Reads from the low level communications channel timing out after the specified time. This is provided for protocols and commands that may need multiple lines and it may not be used in cases (datagram) that are not connection-oriented.

Parameters:
TO - time out value in milliseconds
Returns:
String sent from the client with EOL stripped.
Throws:
ConnectionException - if an error occurs

read

public int read(byte[] data,
                long TO)
         throws ConnectionException,
                java.io.IOException
Read an array-full of data timing out in the specified period.

Throws:
ConnectionException
java.io.IOException

read

public int read(byte[] data)
         throws ConnectionException,
                java.io.IOException
Read an array-full of data.

Throws:
ConnectionException
java.io.IOException

getClientAddress

public java.net.InetAddress getClientAddress()
Provide the client internet address.

Returns:
InetAddress for the client.

getClientPort

public int getClientPort()
Provide the client port.

Returns:
integer port for the client.

getServerPort

public int getServerPort()
Provide the server port often used as ID.

Returns:
integer port for this server.

putLine

public void putLine(java.lang.String ln)
             throws ConnectionException
Sends a single line back to the client. Since it is really a String, it may be formatted in any fashion allowed by Strings. EOL is not added.

Parameters:
ln - a String value
Throws:
ConnectionException - if an error occurs

putLine

public void putLine(java.lang.String ln,
                    java.net.InetAddress cAddress,
                    int cPort)
             throws ConnectionException
Sends a single line back to the client. Since it is really a String, it may be formatted in any fashion allowed by Strings. EOL is not added.

This variant allows the caller to specify the client address and port. This is mostly used with UDP servers.

Parameters:
ln - a String value
cAddress - an InetAddress value
cPort - an int value
Throws:
ConnectionException - if an error occurs

init

public void init()
          throws java.io.IOException
Make sure everything is set up and ready to run.

Throws:
java.io.IOException - if an error occurs

close

public void close()
Shut down cleanly.


reset

public void reset()
           throws java.io.IOException
Flush, close and re-init.

Throws:
java.io.IOException - if an error occurs


Copyright © 2001-2002 MileStone Solutions, Inc. All Rights Reserved.