Class ProxyClient
java.lang.Object
arc.net.Connection
arc.net.Client
com.xpdustry.claj.api.net.ProxyClient
- All Implemented Interfaces:
arc.net.EndPoint, Runnable
- Direct Known Subclasses:
ClajProxy
public abstract class ProxyClient
extends arc.net.Client
A client that act like a server. Discovery is not supported for now (i don't have the use).
The proxy doesn't do all the job:
- Packet reception must be done manually.
- Notifying methods must be called (
- Packet making methods must be defined (
The proxy doesn't do all the job:
- Packet reception must be done manually.
- Notifying methods must be called (
conConnected(int, long), conDisconnected(int, DcReason), conReceived(int, Object) and
conIdle(int)). - Packet making methods must be defined (
makeConWrapPacket(int, Object, boolean) and makeConClosePacket(int, DcReason)).-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanAs packet broadcasting is not a protocol breaking change, some servers may not support it.protected booleanprotected arc.net.NetListenerprotected InetAddressprotected booleanprotected final arc.struct.Seq<VirtualConnection> protected final arc.struct.IntMap<VirtualConnection> protected intprotected intprotected intstatic intprotected arc.func.Cons<Throwable> booleanWhether to force using the tcp connection when sending trough udp to the server.protected longstatic intDelay between pings.protected com.xpdustry.claj.common.net.ClientReceiverprotected booleanprotected booleanprotected intPacket queue to avoid a buffer overflow. -
Constructor Summary
ConstructorsConstructorDescriptionProxyClient(int writeBufferSize, int objectBufferSize, arc.net.NetSerializer serialization) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidintSend an object to every clients connected to the room.protected intbroadcastImpl(Object object, boolean tcp) Doesn't checks for availability.protected voidprotected voidclose(int conId, arc.net.DcReason reason) Can be used notify the server to close the connection when not created by the proxy.voidclose(arc.net.DcReason reason) voidclose(VirtualConnection con, arc.net.DcReason reason) voidcloseAllConnections(arc.net.DcReason reason) voidcloseQuietly(VirtualConnection con, arc.net.DcReason reason) Close connection without notify the server.protected VirtualConnectionconConnected(int conId, long addressHash) protected VirtualConnectionconDisconnected(int conId, arc.net.DcReason reason) protected VirtualConnectionconIdle(int conId) voidconnect(int timeout, InetAddress host, int tcpPort, int udpPort) voidConnect useddefaultTimeoutand sameportfor TCP and UDP.protected VirtualConnectionconReceived(int conId, Object object) voideachConnections(arc.func.Cons<VirtualConnection> consumer) getConnection(int id) protected arc.struct.Seq<VirtualConnection> booleanbooleanprotected abstract ObjectmakeBroadcastClosePacket(arc.net.DcReason reason) protected abstract ObjectmakeBroadcastWrapPacket(Object object, boolean tcp) protected abstract ObjectmakeConClosePacket(int conId, arc.net.DcReason reason) protected abstract ObjectmakeConWrapPacket(int conId, Object object, boolean tcp) protected voidvoidrun()intsend(VirtualConnection con, Object object, boolean tcp) intintintBecause allVirtualConnections shares the same tcp buffer, it can be filled quickly.voidstart()voidstop()voidupdate(int timeout) voidTries to mimic connection idling.voidMethods inherited from class arc.net.Client
close, connect, connect, connect, discoverHosts, dispose, getSerialization, getUpdateThread, reconnect, reconnect, setDiscoveryPacket, setKeepAliveUDPMethods inherited from class arc.net.Connection
addListener, getArbitraryData, getEndPoint, getID, getLastProtocolError, getRemoteAddressTCP, getRemoteAddressUDP, getReturnTripTime, getTcpWriteBufferSize, isConnected, isIdle, removeListener, sendUDP, setArbitraryData, setIdleThreshold, setKeepAliveTCP, setName, setTimeout, toString, updateReturnTripTimeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface arc.net.EndPoint
addListener, removeListener
-
Field Details
-
defaultTimeout
public static int defaultTimeout -
pingTime
public static int pingTimeDelay between pings. -
connectTimeout
protected int connectTimeout -
connectHost
-
connectTcpPort
protected int connectTcpPort -
connectUdpPort
protected int connectUdpPort -
connectionsMap
-
connections
-
conListener
protected arc.net.NetListener conListener -
shutdown
protected volatile boolean shutdown -
starting
protected volatile boolean starting -
connecting
protected volatile boolean connecting -
closing
protected volatile boolean closing -
receiver
protected com.xpdustry.claj.common.net.ClientReceiver receiver -
lastPing
protected long lastPing -
errorHandler
-
writeBufferThreshold
protected int writeBufferThresholdPacket queue to avoid a buffer overflow. -
forceTcp
public boolean forceTcpWhether to force using the tcp connection when sending trough udp to the server.
The server will then send it via udp to the real client.
This can fix some udp packet loss issues, at the cost of increased tcp band for things initially designed to be less important. -
broadcastSupported
public boolean broadcastSupportedAs packet broadcasting is not a protocol breaking change, some servers may not support it.
Server version should be checked and this field set tofalseif not supported.
This field is reset before connecting and after closing the proxy.
-
-
Constructor Details
-
ProxyClient
public ProxyClient(int writeBufferSize, int objectBufferSize, arc.net.NetSerializer serialization)
-
-
Method Details
-
connect
Connect useddefaultTimeoutand sameportfor TCP and UDP.
This also ensures that the client is running before connection.- Throws:
IOException
-
connect
- Overrides:
connectin classarc.net.Client- Throws:
IOException
-
update
- Specified by:
updatein interfacearc.net.EndPoint- Overrides:
updatein classarc.net.Client- Throws:
IOException
-
updateIdle
public void updateIdle()Tries to mimic connection idling. -
updatePing
public void updatePing() -
run
-
start
public void start()- Specified by:
startin interfacearc.net.EndPoint- Overrides:
startin classarc.net.Client
-
stop
public void stop()- Specified by:
stopin interfacearc.net.EndPoint- Overrides:
stopin classarc.net.Client
-
isRunning
public boolean isRunning() -
isConnecting
public boolean isConnecting() -
close
public void close(arc.net.DcReason reason) - Overrides:
closein classarc.net.Connection
-
closeAllConnections
public void closeAllConnections(arc.net.DcReason reason) -
addConnection
-
removeConnection
-
clearConnections
protected void clearConnections() -
getConnection
-
getInternalConnections
-
getConnections
-
eachConnections
-
broadcast
Send an object to every clients connected to the room.
This is an optimization method to avoid the host from sending the same packet to every virtual clients, as the server will do it to the real ones instead. So, using this will save bandwidth. -
broadcastImpl
Doesn't checks for availability. -
send
-
send
-
send
-
close
protected void close(int conId, arc.net.DcReason reason) Can be used notify the server to close the connection when not created by the proxy.
This will not trigger callbacks. -
close
-
closeQuietly
Close connection without notify the server. -
conConnected
- Returns:
- never
null.
-
conDisconnected
-
conReceived
-
conIdle
-
makeBroadcastWrapPacket
-
makeBroadcastClosePacket
-
makeConWrapPacket
-
makeConClosePacket
-
sendTCP
Because allVirtualConnections shares the same tcp buffer, it can be filled quickly.
This will slow down sends when the write buffer reaches a threshold.- Overrides:
sendTCPin classarc.net.Connection
-