public class Client extends Connection implements EndPoint
Server
.Constructor and Description |
---|
Client()
Creates a Client with a write buffer size of 8192 and an object buffer size of 2048.
|
Client(int writeBufferSize,
int objectBufferSize) |
Client(int writeBufferSize,
int objectBufferSize,
Serialization serialization) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(Listener listener)
If the listener already exists, it is not added again.
|
void |
close() |
void |
connect(int timeout,
InetAddress host,
int tcpPort)
Opens a TCP only client.
|
void |
connect(int timeout,
InetAddress host,
int tcpPort,
int udpPort)
Opens a TCP and UDP client.
|
void |
connect(int timeout,
String host,
int tcpPort)
Opens a TCP only client.
|
void |
connect(int timeout,
String host,
int tcpPort,
int udpPort)
Opens a TCP and UDP client.
|
InetAddress |
discoverHost(int udpPort,
int timeoutMillis)
Broadcasts a UDP message on the LAN to discover any running servers.
|
List<InetAddress> |
discoverHosts(int udpPort,
int timeoutMillis)
Broadcasts a UDP message on the LAN to discover any running servers.
|
void |
dispose()
Releases the resources used by this client, which may no longer be used.
|
com.esotericsoftware.kryo.Kryo |
getKryo()
Gets the Kryo instance that will be used to serialize and deserialize objects.
|
Serialization |
getSerialization()
Gets the serialization instance that will be used to serialize and deserialize objects.
|
Thread |
getUpdateThread()
Returns the last thread that called
EndPoint.update(int) for this end point. |
void |
reconnect()
Calls
connect with the values last passed to connect. |
void |
reconnect(int timeout)
Calls
connect with the specified timeout and the other values last passed to
connect. |
void |
removeListener(Listener listener) |
void |
run()
Continually updates this end point until
EndPoint.stop() is called. |
void |
setDiscoveryHandler(ClientDiscoveryHandler newDiscoveryHandler) |
void |
setKeepAliveUDP(int keepAliveMillis)
An empty object will be sent if the UDP connection is inactive more than the specified milliseconds.
|
void |
start()
Starts a new thread that calls
EndPoint.run() . |
void |
stop()
Closes this end point and causes
EndPoint.run() to return. |
void |
update(int timeout)
Reads or writes any pending data for this client.
|
getEndPoint, getID, getRemoteAddressTCP, getRemoteAddressUDP, getReturnTripTime, getTcpWriteBufferSize, isConnected, isIdle, sendTCP, sendUDP, setBufferPositionFix, setIdleThreshold, setKeepAliveTCP, setName, setTimeout, toString, updateReturnTripTime
public Client()
public Client(int writeBufferSize, int objectBufferSize)
writeBufferSize
- One buffer of this size is allocated. Objects are serialized to the write buffer where the bytes are
queued until they can be written to the TCP socket.
Normally the socket is writable and the bytes are written immediately. If the socket cannot be written to and enough serialized objects are queued to overflow the buffer, then the connection will be closed.
The write buffer should be sized at least as large as the largest object that will be sent, plus some head room to allow for some serialized objects to be queued in case the buffer is temporarily not writable. The amount of head room needed is dependent upon the size of objects being sent and how often they are sent.
objectBufferSize
- One (using only TCP) or three (using both TCP and UDP) buffers of this size are allocated. These
buffers are used to hold the bytes for a single object graph until it can be sent over the network or
deserialized.
The object buffers should be sized at least as large as the largest object that will be sent or received.
public Client(int writeBufferSize, int objectBufferSize, Serialization serialization)
public void setDiscoveryHandler(ClientDiscoveryHandler newDiscoveryHandler)
public Serialization getSerialization()
EndPoint
getSerialization
in interface EndPoint
public com.esotericsoftware.kryo.Kryo getKryo()
EndPoint
KryoSerialization
is being used, which is the default.public void connect(int timeout, String host, int tcpPort) throws IOException
IOException
connect(int, InetAddress, int, int)
public void connect(int timeout, String host, int tcpPort, int udpPort) throws IOException
IOException
connect(int, InetAddress, int, int)
public void connect(int timeout, InetAddress host, int tcpPort) throws IOException
IOException
connect(int, InetAddress, int, int)
public void connect(int timeout, InetAddress host, int tcpPort, int udpPort) throws IOException
Because the framework must perform some minimal communication before the connection is considered successful,
update(int)
must be called on a separate thread during the connection process.
IllegalStateException
- if called from the connection's update thread.IOException
- if the client could not be opened or connecting times out.public void reconnect() throws IOException
connect
with the values last passed to connect.IllegalStateException
- if connect has never been called.IOException
public void reconnect(int timeout) throws IOException
connect
with the specified timeout and the other values last passed to
connect.IllegalStateException
- if connect has never been called.IOException
public void update(int timeout) throws IOException
update
in interface EndPoint
timeout
- Wait for up to the specified milliseconds for data to be ready to process. May be zero to return immediately
if there is no data to process.IOException
update(int)
,
Server.update(int)
public void run()
EndPoint
EndPoint.stop()
is called.public void start()
EndPoint
EndPoint.run()
.public void stop()
EndPoint
EndPoint.run()
to return.public void close()
public void dispose() throws IOException
IOException
public void addListener(Listener listener)
Connection
addListener
in interface EndPoint
addListener
in class Connection
public void removeListener(Listener listener)
removeListener
in interface EndPoint
removeListener
in class Connection
public void setKeepAliveUDP(int keepAliveMillis)
public Thread getUpdateThread()
EndPoint
EndPoint.update(int)
for this end point. This can be useful to detect when long running
code will be run on the update thread.getUpdateThread
in interface EndPoint
public InetAddress discoverHost(int udpPort, int timeoutMillis)
udpPort
- The UDP port of the server.timeoutMillis
- The number of milliseconds to wait for a response.public List<InetAddress> discoverHosts(int udpPort, int timeoutMillis)
udpPort
- The UDP port of the server.timeoutMillis
- The number of milliseconds to wait for a response.Copyright © 2014. All Rights Reserved.