Package arc.net
Class Connection
java.lang.Object
arc.net.Connection
- Direct Known Subclasses:
Client
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(NetListener listener) Adds a listener to the connection.void
int
getID()
Returns the server assigned ID.Returns the last protocol error that occured on the connection.Returns the IP address and port of the remote end of the TCP connection, or null if this connection is not connected.Returns the IP address and port of the remote end of the UDP connection, or null if this connection is not connected.int
Returns the last calculated TCP return trip time, or -1 ifupdateReturnTripTime()
has never been called or theFrameworkMessage.Ping
response has not yet been received.int
Returns the number of bytes that are waiting to be written to the TCP socket, if any.boolean
Returns true if this connection is connected to the remote end.boolean
isIdle()
void
removeListener
(NetListener listener) int
Sends the object over the network using TCP.int
Sends the object over the network using UDP.void
setArbitraryData
(Object arbitraryData) void
setIdleThreshold
(float idleThreshold) If the percent of the TCP write buffer that is filled is less than the specified threshold,NetListener.idle(Connection)
will be called for each network thread update.void
setKeepAliveTCP
(int keepAliveMillis) An empty object will be sent if the TCP connection has not sent an object within the specified milliseconds.void
Sets the friendly name of this connection.void
setTimeout
(int timeoutMillis) If the specified amount of time passes without receiving an object over TCP, the connection is considered closed.toString()
void
Requests the connection to communicate with the remote computer to determine a new value for thereturn trip time
.
-
Constructor Details
-
Connection
protected Connection()
-
-
Method Details
-
getID
public int getID()Returns the server assigned ID. Will return -1 if this connection has never been connected or the last assigned ID if this connection has been disconnected. -
isConnected
public boolean isConnected()Returns true if this connection is connected to the remote end. Note that a connection can become disconnected at any time. -
getLastProtocolError
Returns the last protocol error that occured on the connection.- Returns:
- The last protocol error or null if none error occured.
-
sendTCP
Sends the object over the network using TCP.- Returns:
- The number of bytes sent.
-
sendUDP
Sends the object over the network using UDP.- Returns:
- The number of bytes sent.
- Throws:
IllegalStateException
- if this connection was not opened with both TCP and UDP.
-
close
-
updateReturnTripTime
public void updateReturnTripTime()Requests the connection to communicate with the remote computer to determine a new value for thereturn trip time
. When the connection receives aFrameworkMessage.Ping
object withisReply
set to true, the new return trip time is available. -
getReturnTripTime
public int getReturnTripTime()Returns the last calculated TCP return trip time, or -1 ifupdateReturnTripTime()
has never been called or theFrameworkMessage.Ping
response has not yet been received. -
setKeepAliveTCP
public void setKeepAliveTCP(int keepAliveMillis) An empty object will be sent if the TCP connection has not sent an object within the specified milliseconds. Periodically sending a keep alive ensures that an abnormal close is detected in a reasonable amount of time (seesetTimeout(int)
). Also, some network hardware will close a TCP connection that ceases to transmit for a period of time (typically 1+ minutes). Set to zero to disable. Defaults to 8000. -
setTimeout
public void setTimeout(int timeoutMillis) If the specified amount of time passes without receiving an object over TCP, the connection is considered closed. When a TCP socket is closed normally, the remote end is notified immediately and this timeout is not needed. However, if a socket is closed abnormally (eg, power loss), ArcNet uses this timeout to detect the problem. The timeout should be set higher than theTCP keep alive
for the remote end of the connection. The keep alive ensures that the remote end of the connection will be constantly sending objects, and setting the timeout higher than the keep alive allows for network latency. Set to zero to disable. Defaults to 12000. -
addListener
Adds a listener to the connection. If the listener already exists, it is not added again.- Parameters:
listener
- The listener to add.
-
removeListener
-
getEndPoint
-
getRemoteAddressTCP
Returns the IP address and port of the remote end of the TCP connection, or null if this connection is not connected. -
getRemoteAddressUDP
Returns the IP address and port of the remote end of the UDP connection, or null if this connection is not connected. -
setName
Sets the friendly name of this connection. This is returned bytoString()
and is useful for providing application specific identifying information in the logging. May be null for the default name of "Connection X", where X is the connection ID. -
getTcpWriteBufferSize
public int getTcpWriteBufferSize()Returns the number of bytes that are waiting to be written to the TCP socket, if any. -
isIdle
public boolean isIdle()- See Also:
-
setIdleThreshold
public void setIdleThreshold(float idleThreshold) If the percent of the TCP write buffer that is filled is less than the specified threshold,NetListener.idle(Connection)
will be called for each network thread update. Default is 0.1. -
toString
-
getArbitraryData
-
setArbitraryData
-