Class Client
Server.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetAddressprotected intprotected intprotected intprotected booleanprotected final NetSerializerprotected booleanprotected booleanprotected booleanFields inherited from class arc.net.Connection
lastPingID, lastPingSendTime, listeners, name, returnTripTime -
Constructor Summary
ConstructorsConstructorDescriptionClient(int writeBufferSize, int objectBufferSize, NetSerializer serialization) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidOpens a TCP only client.voidOpens a TCP and UDP client.voidconnect(int timeout, InetAddress host, int tcpPort) Opens a TCP only client.voidconnect(int timeout, InetAddress host, int tcpPort, int udpPort) Opens a TCP and UDP client.voiddiscoverHosts(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.voiddispose()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.voidvoidCallsconnectwith the values last passed to connect.voidreconnect(int timeout) Callsconnectwith the specified timeout and the other values last passed to connect.voidrun()Continually updates this end point untilEndPoint.stop()is called.voidsetDiscoveryPacket(Prov<DatagramPacket> discoveryPacket) voidsetKeepAliveUDP(int keepAliveMillis) An empty object will be sent if the UDP connection is inactive more than the specified milliseconds.voidstart()Starts a new thread that callsEndPoint.run().voidstop()Closes this end point and causesEndPoint.run()to return.voidupdate(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, notifyConnected, notifyDisconnected, notifyIdle, notifyReceived, removeListener, sendTCP, sendUDP, setArbitraryData, setIdleThreshold, setKeepAliveTCP, setName, setTimeout, toString, updateReturnTripTimeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface arc.net.EndPoint
addListener, removeListener
-
Field Details
-
serialization
-
tcpRegistered
protected volatile boolean tcpRegistered -
udpRegistered
protected volatile boolean udpRegistered -
shutdown
protected volatile boolean shutdown -
connectTimeout
protected int connectTimeout -
connectHost
-
connectTcpPort
protected int connectTcpPort -
connectUdpPort
protected int connectUdpPort -
isClosed
protected boolean isClosed
-
-
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
Callsconnectwith the values last passed to connect.- Throws:
IllegalStateException- if connect has never been called.IOException
-
reconnect
Callsconnectwith 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:
updatein 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:
-
handleNetException
-
run
public void run()Description copied from interface:EndPointContinually updates this end point untilEndPoint.stop()is called. -
start
public void start()Description copied from interface:EndPointStarts a new thread that callsEndPoint.run(). -
stop
public void stop()Description copied from interface:EndPointCloses 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:EndPointReturns 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:
getUpdateThreadin 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.
-