kom.tools.ipc
Class IPCConnection

java.lang.Object
  |
  +--kom.tools.ipc.IPCConnection

public class IPCConnection
extends java.lang.Object

This is a connection between a client and a server. The connection exists on both network sides. One will be generated on the client side when the client attempts to connect a server. Another connection will be generated on the server side when the server accepts a connection from the client.


Field Summary
protected  java.io.InputStream inputStream
          The stream for reading data
protected  java.io.OutputStream outputStream
          The stream for sending data
 java.net.Socket socket
          The communication socket
 
Constructor Summary
IPCConnection(java.net.Socket s)
          Class constructor
 
Method Summary
 int available()
          Checks for available data on the socket
 void close()
          Closes the current connection
 java.io.InputStream getInputStream()
          Returns the input stream
 java.io.OutputStream getOutputStream()
          Returns the output stream
 int read(byte[] buffer, int size)
          Waits for data and receives it (blocks until data available)
 int read(IPCBuffer buffer)
          Waits for data and receives it (blocks until data available)
 java.lang.String readLine()
          Reads a line of data from the input stream
 boolean write(byte[] data)
          Sends data over the network
 boolean write(IPCBuffer buffer)
          Sends data over the network
 boolean write(java.lang.String data)
          Sends data over the network
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

socket

public java.net.Socket socket
The communication socket

inputStream

protected java.io.InputStream inputStream
The stream for reading data

outputStream

protected java.io.OutputStream outputStream
The stream for sending data
Constructor Detail

IPCConnection

public IPCConnection(java.net.Socket s)
Class constructor
Parameters:
s - the communication socket
Method Detail

available

public int available()
Checks for available data on the socket
Returns:
The number of bytes available or -1

read

public int read(IPCBuffer buffer)
Waits for data and receives it (blocks until data available)
Parameters:
buffer - Storage for the data received
Returns:
The number of bytes received or -1 when an error occurred.

read

public int read(byte[] buffer,
                int size)
Waits for data and receives it (blocks until data available)
Parameters:
buffer - Storage for the data received
size - Max used size of buffer
Returns:
The number of bytes received or -1 when an error occurred.

readLine

public java.lang.String readLine()
Reads a line of data from the input stream
Returns:
line or null

write

public boolean write(IPCBuffer buffer)
Sends data over the network
Parameters:
buffer - data to be sent
Returns:
true if action was ok

write

public boolean write(byte[] data)
Sends data over the network
Parameters:
data - data to be sent
Returns:
True if action was ok, false otherwise.

write

public boolean write(java.lang.String data)
Sends data over the network
Parameters:
data - data to be sent
Returns:
True if action was ok, false otherwise.

close

public void close()
Closes the current connection

getInputStream

public java.io.InputStream getInputStream()
Returns the input stream

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the output stream