Modifier | Constructor and Description |
---|---|
protected |
Connection() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Listener listener)
If the listener already exists, it is not added again.
|
void |
close() |
EndPoint |
getEndPoint()
|
int |
getID()
Returns the server assigned ID.
|
InetSocketAddress |
getRemoteAddressTCP()
Returns the IP address and port of the remote end of the TCP connection, or null if this connection is not connected.
|
InetSocketAddress |
getRemoteAddressUDP()
Returns the IP address and port of the remote end of the UDP connection, or null if this connection is not connected.
|
int |
getReturnTripTime()
Returns the last calculated TCP return trip time, or -1 if
updateReturnTripTime() has never been called or the
FrameworkMessage.Ping response has not yet been received. |
int |
getTcpWriteBufferSize()
Returns the number of bytes that are waiting to be written to the TCP socket, if any.
|
boolean |
isConnected()
Returns true if this connection is connected to the remote end.
|
boolean |
isIdle() |
void |
removeListener(Listener listener) |
int |
sendTCP(Object object)
Sends the object over the network using TCP.
|
int |
sendUDP(Object object)
Sends the object over the network using UDP.
|
void |
setBufferPositionFix(boolean bufferPositionFix)
Workaround for broken NIO networking on Android 1.6.
|
void |
setIdleThreshold(float idleThreshold)
If the percent of the TCP write buffer that is filled is less than the specified threshold,
Listener.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 |
setName(String name)
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.
|
String |
toString() |
void |
updateReturnTripTime()
Requests the connection to communicate with the remote computer to determine a new value for the
return trip time . |
public int getID()
public boolean isConnected()
public int sendTCP(Object object)
Kryo.register(Class, com.esotericsoftware.kryo.Serializer)
public int sendUDP(Object object)
IllegalStateException
- if this connection was not opened with both TCP and UDP.Kryo.register(Class, com.esotericsoftware.kryo.Serializer)
public void close()
public void updateReturnTripTime()
return trip time
. When the connection receives a FrameworkMessage.Ping
object with
isReply
set to true, the new return trip time is available.public int getReturnTripTime()
updateReturnTripTime()
has never been called or the
FrameworkMessage.Ping
response has not yet been received.public void setKeepAliveTCP(int keepAliveMillis)
setTimeout(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.public void setTimeout(int timeoutMillis)
TCP 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.public void addListener(Listener listener)
public void removeListener(Listener listener)
public EndPoint getEndPoint()
public InetSocketAddress getRemoteAddressTCP()
public InetSocketAddress getRemoteAddressUDP()
public void setBufferPositionFix(boolean bufferPositionFix)
public void setName(String name)
toString()
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.public int getTcpWriteBufferSize()
public boolean isIdle()
setIdleThreshold(float)
public void setIdleThreshold(float idleThreshold)
Listener.idle(Connection)
will be called for each network thread update. Default is 0.1.Copyright © 2014. All Rights Reserved.