communication
Class TCPElement

java.lang.Object
  extended by communication.TCPElement

public class TCPElement
extends java.lang.Object

Class used by communication element: manage communications through TCP sockets


Field Summary
protected  int localPort
          The port on which the local socket server is bound
protected  java.net.ServerSocket serverSocket
          The local socket server of the element
 
Constructor Summary
TCPElement(int localPort)
           
 
Method Summary
 int getLocalPort()
           
 boolean initTCP()
          Initialize the TCP server socket
 Message receiveData()
          Wait for the next received message coming from any remote process
 void sendData(java.net.InetAddress adr, int port, java.lang.Object data)
          Send data through the TCP socket.
 void setLocalPort(int localPort)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverSocket

protected java.net.ServerSocket serverSocket
The local socket server of the element


localPort

protected int localPort
The port on which the local socket server is bound

Constructor Detail

TCPElement

public TCPElement(int localPort)
Parameters:
localPort - the port on which the server socket has to be bound
Method Detail

sendData

public void sendData(java.net.InetAddress adr,
                     int port,
                     java.lang.Object data)
              throws CommunicationException
Send data through the TCP socket.

Parameters:
adr - IP address of the remote element
port - port used by the server socket of the remote element
data - data to send
Throws:
CommunicationException - in case of communication problem

receiveData

public Message receiveData()
Wait for the next received message coming from any remote process

Returns:
the next received message

initTCP

public boolean initTCP()
Initialize the TCP server socket

Returns:
true if the server socket has been bound to the required port, false otherwise (the TCP element is not usable).

getLocalPort

public int getLocalPort()
Returns:
the localPort

setLocalPort

public void setLocalPort(int localPort)
Parameters:
localPort - the localPort to set