public class TcpNode
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
GET_PERSONAL_NODE
Relay request for reclaiming the nickname of the requesting node.
|
static java.lang.String |
GET_SERVER_STATUS
Relay request for reclaiming the current server status.
|
Constructor and Description |
---|
TcpNode()
Creates a TcpNode that will use the relay and port defined in the
TcpProperties file.
|
TcpNode(java.lang.String relay,
int port)
Creates a TcpNode that will use the given relay listening on the given ip port.
|
TcpNode(java.lang.String relay,
int port,
java.lang.String relayID)
Creates a TcpNode that will use the given relay listening on the given ip port.
|
TcpNode(java.lang.String relay,
int port,
java.lang.String proxy,
int proxyPort)
Creates a TcpNode that will use the given relay listening on the given ip port.
|
TcpNode(java.lang.String relay,
int port,
java.lang.String relayID,
java.lang.String proxy,
int proxyPort)
Creates a TcpNode that will use the given relay listening on the given ip port.
|
Modifier and Type | Method and Description |
---|---|
void |
addTcpNodeListener(TcpNodeListener listener)
Registers a TcpNodeListener to get connection and data notifications.
|
void |
connect(java.lang.String sessionID,
java.lang.String nickname)
Same as connect(sessionID, nickname, 1, 1, 1):
|
void |
connect(java.lang.String sessionID,
java.lang.String nickname,
int connectTag,
int disconnectTag,
int newNodeTag)
If the connect state is TcpNodeState.DISCONNECTED, sets the state to
TcpNodeState.CONNECTING and lauches a connection trial, then returns.
|
void |
disconnect()
Disconnects from the relay.
|
long |
getClockTime()
Returns current time of internal clock synchronized with the relay's clock (in ms).
|
java.lang.String |
getNickname()
Returns the requested agent nickname when connecting to the relay.
|
TcpNodeState |
getNodeState()
Returns the node state.
|
int |
getPort()
Returns the IP port number used by the relay server.
|
java.lang.String |
getRelay()
Returns the IP address of the relay server.
|
java.lang.String |
getVersion()
Returns current version information of TcpJLib.
|
void |
sendIntMessage(int... data)
Sends an integer array to all node by concatenating each number
with a '&' separator (no trailing '&').
|
void |
sendIntMessage(java.lang.String destination,
int... data)
Sends an integer array to the destination nodes (except the sending node)
by concatenating each number with a '&' separator (no trailing '&').
|
void |
sendMessage(java.lang.String line)
Sends a message to all nodes (except the sending node)
in the same sessions (via the relay).
|
void |
sendMessage(java.lang.String destination,
java.lang.String line)
Sends a message to the given destination node (via the relay).
|
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 static final java.lang.String GET_SERVER_STATUS
public static final java.lang.String GET_PERSONAL_NODE
public TcpNode(java.lang.String relay, int port, java.lang.String relayID, java.lang.String proxy, int proxyPort)
relay
- the URL of the relayport
- the IP port of the relayrelayID
- the ID of the relayproxy
- the URL of the proxyproxyPort
- the IP port of the proxypublic TcpNode(java.lang.String relay, int port, java.lang.String relayID)
relay
- the URL of the relayport
- the IP port of the relayrelayID
- the ID of the relaypublic TcpNode(java.lang.String relay, int port, java.lang.String proxy, int proxyPort)
relay
- the URL of the relayport
- the IP port of the relayproxy
- the URL of the proxyproxyPort
- the IP port of the proxypublic TcpNode(java.lang.String relay, int port)
relay
- the URL of the relayport
- the IP port of the relaypublic TcpNode()
public void connect(java.lang.String sessionID, java.lang.String nickname, int connectTag, int disconnectTag, int newNodeTag)
sessionID
- a unique session ID that binds all node in the same session together.
Characters < 32 and > 127 ignorednickname
- a name that characterizes the node. If two nodes requests the same
name, the relay appends an increasing version number (n).
Characters < 32 and > 127 ignoredconnectTag
- 0: no report, 1: report nickname, 2: report ip address + nickname;
otherwise same as 0disconnectTag
- 0: no report, 1: report nickname, 2: report ip address + nickname;
otherwise same as 0newNodeTag
- 0: no report, 1: report nickname, 2: report ip address + nickname;
otherwise same as 0public void connect(java.lang.String sessionID, java.lang.String nickname)
sessionID
- a unique session ID that binds all node in the same session together.
Characters < 32 and > 127 ignorednickname
- a name that characterizes the node. If two nodes requests the same
name, the relay appends an increasing version number (n).
Characters < 32 and > 127 ignoredpublic java.lang.String getNickname()
public void sendMessage(java.lang.String line)
line
- the data to send to all other nodespublic void sendMessage(java.lang.String destination, java.lang.String line)
destination
- the nickname (attributed by the relay)
of the destination nodeline
- the data to sendpublic void sendIntMessage(java.lang.String destination, int... data)
data
- the integer array to sendpublic void sendIntMessage(int... data)
data
- the integer array to sendpublic int sendSynchRequest()
public void sendRelayRequest(java.lang.String request)
request
- one the the static request constants defined in class TcpNodepublic void disconnect()
public TcpNodeState getNodeState()
public void addTcpNodeListener(TcpNodeListener listener)
listener
- the listener to registerpublic java.lang.String getRelay()
public int getPort()
public java.lang.String getVersion()
public long getClockTime()