synapsi.net
Class Connection


java.lang.Object

  |

  +--synapsi.net.Connection


public class Connection
extends java.lang.Object

Implement connection class for simple access to TPC/IP sockets


Field Summary
static int STATUS_CONNECTED
           
static int STATUS_ERROR
           
static int STATUS_NOCONNECTION
           
 
Constructor Summary
Connection(java.lang.String sIP, int nPort)
          Connection constructor creates socket and connects it to specified client and port
 
Method Summary
 int close()
          Close and destroy socket
 java.lang.String readLine(int nTimeout)
          Reads a line of text from the socket.
 int readUnsignedByte(int nTimeout)
          Read bytes from socket
 int receive(byte[] bBytes, int nTimeout)
          Read bytes from socket
 int send(byte[] bBytes)
          Send bytes to socket
 int send(byte[] bBytes, int lLen)
          Send bytes to socket
 int writeLine(java.lang.String sLine)
          Writes a line to the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_NOCONNECTION


public static final int STATUS_NOCONNECTION

STATUS_CONNECTED


public static final int STATUS_CONNECTED

STATUS_ERROR


public static final int STATUS_ERROR
Constructor Detail

Connection


public Connection(java.lang.String sIP,
                  int nPort)
Connection constructor creates socket and connects it to specified client and port
Parameters:
sIP - address of client
nPort - port to connect to
Method Detail

readLine


public java.lang.String readLine(int nTimeout)
Reads a line of text from the socket. Line terminates with a linefeed (0x0a)
Parameters:
nTimeout - timeout in milliseconds
Returns:
line read from the socket, null if error

writeLine


public int writeLine(java.lang.String sLine)
Writes a line to the socket. If the string does not contain a linefeed at the end, a linefeed is added.
Parameters:
sLine - line to be written
Returns:
number of bytes written or negative if error

send


public int send(byte[] bBytes)
Send bytes to socket
Parameters:
bBytes - bytes to be sent
Returns:
number of bytes written or negative if error

send


public int send(byte[] bBytes,
                int lLen)
Send bytes to socket
Parameters:
bBytes - bytes to be sent
lLen - number of bytes to send
Returns:
number of bytes written, negative if error

receive


public int receive(byte[] bBytes,
                   int nTimeout)
Read bytes from socket
Parameters:
bBytes - buffer to read bytes to
nTimeout - timeout in milliseconds
Returns:
number of bytes read, negative if error

readUnsignedByte


public int readUnsignedByte(int nTimeout)
Read bytes from socket
Parameters:
bBytes - buffer to read bytes to
nTimeout - timeout in milliseconds
Returns:
number of bytes read, negative if error

close


public int close()
Close and destroy socket
Returns:
zero if success, negative if error