Class Client
Server
.-
Constructor Summary
ConstructorDescriptionClient
(int writeBufferSize, int objectBufferSize, NetSerializer serialization) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Opens a TCP only client.void
Opens a TCP and UDP client.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
discoverHosts
(int udpPort, String multicastGroup, int multicastPort, int timeoutMillis, Cons<DatagramPacket> handler, Runnable done) 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.Returns the last thread that calledEndPoint.update(int)
for this end point.void
Callsconnect
with the values last passed to connect.void
reconnect
(int timeout) Callsconnect
with the specified timeout and the other values last passed to connect.void
run()
Continually updates this end point untilEndPoint.stop()
is called.void
setDiscoveryPacket
(Prov<DatagramPacket> discoveryPacket) 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 callsEndPoint.run()
.void
stop()
Closes this end point and causesEndPoint.run()
to return.void
update
(int timeout) Reads or writes any pending data for this client.Methods inherited from class arc.net.Connection
addListener, close, getArbitraryData, getEndPoint, getID, getLastProtocolError, getRemoteAddressTCP, getRemoteAddressUDP, getReturnTripTime, getTcpWriteBufferSize, isConnected, isIdle, removeListener, sendTCP, sendUDP, setArbitraryData, setIdleThreshold, setKeepAliveTCP, setName, setTimeout, toString, updateReturnTripTime
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface arc.net.EndPoint
addListener, removeListener
-
Constructor Details
-
Client
- Parameters:
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.
-
-
Method Details
-
setDiscoveryPacket
-
connect
Opens a TCP only client.- Throws:
IOException
- See Also:
-
connect
Opens a TCP and UDP client.- Throws:
IOException
- See Also:
-
connect
Opens a TCP only client.- Throws:
IOException
- See Also:
-
connect
Opens a TCP and UDP client. Blocks until the connection is complete or the timeout is reached.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.- Throws:
IllegalStateException
- if called from the connection's update thread.IOException
- if the client could not be opened or connecting times out.
-
reconnect
Callsconnect
with the values last passed to connect.- Throws:
IllegalStateException
- if connect has never been called.IOException
-
reconnect
Callsconnect
with the specified timeout and the other values last passed to connect.- Throws:
IllegalStateException
- if connect has never been called.IOException
-
update
Reads or writes any pending data for this client. Multiple threads should not call this method at the same time.- Specified by:
update
in interfaceEndPoint
- Parameters:
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.- Throws:
IOException
- See Also:
-
run
public void run()Description copied from interface:EndPoint
Continually updates this end point untilEndPoint.stop()
is called. -
start
public void start()Description copied from interface:EndPoint
Starts a new thread that callsEndPoint.run()
. -
stop
public void stop()Description copied from interface:EndPoint
Closes this end point and causesEndPoint.run()
to return. -
close
public void close() -
dispose
Releases the resources used by this client, which may no longer be used.- Throws:
IOException
-
setKeepAliveUDP
public void setKeepAliveUDP(int keepAliveMillis) An empty object will be sent if the UDP connection is inactive more than the specified milliseconds. Network hardware may keep a translation table of inside to outside IP addresses and a UDP keep alive keeps this table entry from expiring. Set to zero to disable. Defaults to 19000. -
getUpdateThread
Description copied from interface:EndPoint
Returns the last thread that calledEndPoint.update(int)
for this end point. This can be useful to detect when long running code will be run on the update thread.- Specified by:
getUpdateThread
in interfaceEndPoint
-
getSerialization
-
discoverHosts
public void discoverHosts(int udpPort, String multicastGroup, int multicastPort, int timeoutMillis, Cons<DatagramPacket> handler, Runnable done) Broadcasts a UDP message on the LAN to discover any running servers.- Parameters:
udpPort
- The UDP port of the server.timeoutMillis
- The number of milliseconds to wait for a response.
-