org.exolab.core.ipc
Class TcpService

java.lang.Object
  extended byorg.exolab.core.ipc.TcpService
All Implemented Interfaces:
IpcIfc

public class TcpService
extends java.lang.Object
implements IpcIfc

Implement a standard Tcp service, with one send and one receive buffer. add a 10 second timeout on the send buffer in case of failures. Receive buffers are blocking, but can have any parameters set as required by getting the underlying soket and setting parameters as required.

Version:
$Revision: 1.5 $ $Date: 2001/05/20 10:49:35 $
Author:
Jim Mourikis
See Also:
IpcIfc, Client, TcpServerService

Field Summary
static int DEFAULT_PORT
           
static java.lang.String LOCAL_HOST
           
static int TIMEOUT
           
 
Constructor Summary
TcpService()
          Default Constructor connects to the local machine on the default port address.
TcpService(java.net.Socket sock)
          Constructor keeps socket reference, and initialises input output streams for the socket.
TcpService(java.lang.String host, int port)
          Attempts to connect to the given host on the given port address.
 
Method Summary
 void close()
          Close the socket connection, and perform any necessary cleanup.
 java.net.Socket getSocket()
          Return the socket reference.
 java.lang.Object receive()
          An object is received on the socket.
 void send(java.io.Serializable ob)
          Send the specified object.
 java.lang.String toString()
          Retrieve a unique id for this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIMEOUT

public static final int TIMEOUT
See Also:
Constant Field Values

LOCAL_HOST

public static final java.lang.String LOCAL_HOST
See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values
Constructor Detail

TcpService

public TcpService()
           throws java.rmi.UnknownHostException,
                  java.io.IOException
Default Constructor connects to the local machine on the default port address.


TcpService

public TcpService(java.lang.String host,
                  int port)
           throws java.rmi.UnknownHostException,
                  java.io.IOException
Attempts to connect to the given host on the given port address.

Parameters:
host - The host to connect to.
port - The port to connect on.
Throws:
TcpConnectionError - if the connection fails.
java.rmi.UnknownHostException
java.io.IOException

TcpService

public TcpService(java.net.Socket sock)
           throws java.io.IOException
Constructor keeps socket reference, and initialises input output streams for the socket.

Parameters:
sock - The socket to monitor.
Method Detail

getSocket

public java.net.Socket getSocket()
Return the socket reference. This should only be used for setting socket options. DO not shutdown the socket directly. Use the close option below.

Returns:
The socket reference this TcpService object contains.

close

public void close()
           throws java.io.IOException
Close the socket connection, and perform any necessary cleanup.

Specified by:
close in interface IpcIfc
Throws:
java.io.IOException - If the socket encounters an error.

send

public void send(java.io.Serializable ob)
          throws java.io.IOException
Send the specified object. First serialize the object, then send the length of the data followed by the data stream.

Specified by:
send in interface IpcIfc
Parameters:
ob - The object to send. Must be serializable.
Throws:
java.io.IOException - If the data fails to write to the output stream.

receive

public java.lang.Object receive()
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
An object is received on the socket. Read the size, then read the data.

Specified by:
receive in interface IpcIfc
Returns:
Object The object received.
Throws:
java.io.IOException - If the data cannot be received.
java.lang.ClassNotFoundException - If the class cannot be re-constituted.

toString

public java.lang.String toString()
Retrieve a unique id for this connection.

Specified by:
toString in interface IpcIfc


Copyright © 1999-2005 The Exolab Group. All Rights Reserved.