public class TcpAgent
extends java.lang.Object
Constructor and Description |
---|
TcpAgent(java.lang.String relay,
int port,
java.lang.String relayID,
java.lang.String sessionID,
java.lang.String bridgeName)
Create a TcpAgent instance for communications between agents using the
given bridge.
|
TcpAgent(java.lang.String sessionID,
java.lang.String bridgeName)
Creates a TcpAgent instance for communications between agents.
|
Modifier and Type | Method and Description |
---|---|
void |
addTcpAgentListener(TcpAgentListener listener)
Registers a TcpAgentListener that reports data reception
and connection state changes.
|
java.util.ArrayList<java.lang.String> |
connectToRelay(java.lang.String agentName)
Same as connectToRelay(agentName, timeout), but waits infinitely for connection.
|
java.util.ArrayList<java.lang.String> |
connectToRelay(java.lang.String agentName,
int timeout)
Connects the agent to the tunneling relay, sessionID,
requested nickname and timeout.
|
void |
disconnect()
Disconnects the agent from the tunneling relay.
|
java.lang.String |
getAgentName()
Returns the requested agent nickname when connecting to the relay.
|
long |
getClockTime()
Returns current time of internal clock synchronized with the relay's clock (in ms).
|
java.lang.String |
getPersonalName()
Returns the nickname attributed by the relay after successful connection.
|
int |
getPort()
Returns the IP port number used by the relay server.
|
java.lang.String |
getRelay()
Returns the IP address of the relay server.
|
TcpNode |
getTcpNode()
Returns the TcpNode reference responsible for the connection.
|
java.lang.String |
getVersion()
Returns current version information of TcpJLib.
|
boolean |
isBridgeConnected()
Returns true, if the bridge is connected to the relay.
|
boolean |
isConnected()
Returns true, if the connection to the relay is established.
|
void |
send(java.lang.String destination,
int... data)
Send data to bridge including a destination agent indicator.
|
void |
sendCommand(java.lang.String destination,
int command,
int... data)
Send data to bridge including a destination agent indicator.
|
void |
sendRelayRequest(java.lang.String request)
Sends a request to the relay.
|
int |
sendSynchRequest()
Sends a clock synchronization request on a new TCP/IP channel
(not influenced by the current traffic between the relay and the node).
|
public TcpAgent(java.lang.String relay, int port, java.lang.String relayID, java.lang.String sessionID, java.lang.String bridgeName)
bridgeName
- the nickname of the bridgepublic TcpAgent(java.lang.String sessionID, java.lang.String bridgeName)
public java.util.ArrayList<java.lang.String> connectToRelay(java.lang.String agentName, int timeout)
agentName
- nickname of the current agent, may be appended by (n)
if the same nickname already existstimeout
- in ms; if <= 0, wait infinitely for connectionpublic java.util.ArrayList<java.lang.String> connectToRelay(java.lang.String agentName)
agentName
- nickname of the current agent, may be appended by (n)
if the same nickname already existspublic void disconnect()
public void send(java.lang.String destination, int... data)
destination
- the nickname of a agent to whom the bridge
should send data, may be an emtpy string to indicate that
the bridge decides where to send data (null set to empty string)
For transmission (using the internal TcpNode) the integer array
is converted into a string where each integer is separated by '&'.
The string length is restricted to 500 characters for security reasons
(relaying stopped, if exceeded).data
- an integer array or any number of integerspublic void sendCommand(java.lang.String destination, int command, int... data)
destination
- the nickname of a agent to whom the bridge
should send data, may be an emtpy string to indicate that
the bridge decides where to send data (null set to empty string)
For transmission (using the internal TcpNode) the integer array
is converted into a string where each integer is separated by '&'.
The string length is restricted to 500 characters for security reasons
(relaying stopped, if exceeded).command
- an integer that is interpreted as command tagdata
- an integer array or any number of integerspublic void sendRelayRequest(java.lang.String request)
request
- a string representing the request as defined as
static in class TcpNodepublic void addTcpAgentListener(TcpAgentListener listener)
listener
- the listener to registerpublic java.lang.String getAgentName()
public java.lang.String getPersonalName()
public boolean isBridgeConnected()
public boolean isConnected()
public java.lang.String getRelay()
public int getPort()
public java.lang.String getVersion()
public long getClockTime()
public int sendSynchRequest()
public TcpNode getTcpNode()