Class DefaultClient
java.lang.Object
com.jme3.network.base.DefaultClient
- All Implemented Interfaces:
Client, MessageConnection
- Direct Known Subclasses:
Network.NetworkClientImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classBridges connector callbacks back into this client instance. -
Field Summary
Fields inherited from interface MessageConnection
CHANNEL_DEFAULT_RELIABLE, CHANNEL_DEFAULT_UNRELIABLE -
Constructor Summary
ConstructorsConstructorDescriptionDefaultClient(String gameName, int version) Creates a client with the specified game name and protocol version.DefaultClient(String gameName, int version, Connector reliable, Connector fast, ConnectorFactory connectorFactory) Creates a client with preconfigured reliable and optional fast connectors. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientStateListener(ClientStateListener listener) Adds a listener that will be notified about connection state changes.voidaddErrorListener(ErrorListener<? super Client> listener) Adds a listener that will be notified when any connection errors occur.voidaddMessageListener(MessageListener<? super Client> listener) Adds a listener that will be notified when any message or object is received from the server.voidaddMessageListener(MessageListener<? super Client> listener, Class... classes) Adds a listener that will be notified when messages of the specified types are received.protected voidAdds the default client services.protected voidEnsures the client has been started.voidclose()Closes this connection to the server.protected voidCloses all connectors and terminates client services.protected voidconfigureChannels(long tempId, int[] ports) Configures any additional channels announced by the server.protected voidDispatches a received message, handling connection-management messages internally.protected voidNotifies registered state listeners that the client connected.protected voidNotifies registered state listeners that the client disconnected.Returns the 'game name' for servers to which this client should be able to connect.intgetId()Returns a unique ID for this client within the remote server or -1 if this client isn't fully connected to the server.Returns the manager for client services.intReturns the game-specific version of the server this client should be able to connect to.protected voidEither calls the ErrorListener or closes the connection if there are no listeners.booleanReturns true if this client is fully connected to the host.booleanReturns true if this client has been started and is still running.voidremoveClientStateListener(ClientStateListener listener) Removes a previously registered connection listener.voidremoveErrorListener(ErrorListener<? super Client> listener) Removes a previously registered error listener.voidremoveMessageListener(MessageListener<? super Client> listener) Removes a previously registered wildcard listener.voidremoveMessageListener(MessageListener<? super Client> listener, Class... classes) Removes a previously registered type-specific listener from the specified types.voidSends a message to the other end of the connection using the specified alternate channel.protected voidSends a message over a specific internal channel.voidSends a message to the server.protected voidsetPrimaryConnectors(Connector reliable, Connector fast, ConnectorFactory connectorFactory) Sets the primary transport connectors used by this client.voidstart()Starts the client allowing it to begin processing incoming messages and delivering them to listeners.protected voidStarts the client services after connection setup completes.protected voidBlocks until the client finishes connecting.
-
Constructor Details
-
DefaultClient
Creates a client with the specified game name and protocol version.- Parameters:
gameName- the expected game nameversion- the expected protocol version
-
DefaultClient
public DefaultClient(String gameName, int version, Connector reliable, Connector fast, ConnectorFactory connectorFactory) Creates a client with preconfigured reliable and optional fast connectors.- Parameters:
gameName- the expected game nameversion- the expected protocol versionreliable- the reliable transport connectorfast- the optional fast transport connectorconnectorFactory- the factory used for any additional channels
-
-
Method Details
-
addStandardServices
protected void addStandardServices()Adds the default client services. -
setPrimaryConnectors
protected void setPrimaryConnectors(Connector reliable, Connector fast, ConnectorFactory connectorFactory) Sets the primary transport connectors used by this client.- Parameters:
reliable- the reliable connectorfast- the optional fast connectorconnectorFactory- the factory used for additional channels
-
checkRunning
protected void checkRunning()Ensures the client has been started. -
start
-
isStarted
-
waitForConnected
protected void waitForConnected()Blocks until the client finishes connecting. -
isConnected
public boolean isConnected()Description copied from interface:ClientReturns true if this client is fully connected to the host.- Specified by:
isConnectedin interfaceClient- Returns:
- true if the client is connected to the server
-
getId
-
getGameName
Description copied from interface:ClientReturns the 'game name' for servers to which this client should be able to connect. This should match the 'game name' set on the server or this client will be turned away.- Specified by:
getGameNamein interfaceClient- Returns:
- the configured game name
-
getVersion
public int getVersion()Description copied from interface:ClientReturns the game-specific version of the server this client should be able to connect to.- Specified by:
getVersionin interfaceClient- Returns:
- the expected game protocol version
-
getServices
Description copied from interface:ClientReturns the manager for client services. Client services extend the functionality of the client.- Specified by:
getServicesin interfaceClient- Returns:
- the client service manager
-
send
-
send
Description copied from interface:ClientSends a message to the other end of the connection using the specified alternate channel.- Specified by:
sendin interfaceClient- Specified by:
sendin interfaceMessageConnection- Parameters:
channel- the transport channel to usemessage- the message to send
-
send
Sends a message over a specific internal channel.- Parameters:
channel- the internal channel indexmessage- the message to sendwaitForConnected- true to wait until the client is connected first
-
close
-
closeConnections
Closes all connectors and terminates client services.- Parameters:
info- optional disconnect information to report to listeners
-
addClientStateListener
Description copied from interface:ClientAdds a listener that will be notified about connection state changes.- Specified by:
addClientStateListenerin interfaceClient- Parameters:
listener- the listener to add
-
removeClientStateListener
Description copied from interface:ClientRemoves a previously registered connection listener.- Specified by:
removeClientStateListenerin interfaceClient- Parameters:
listener- the listener to remove
-
addMessageListener
Description copied from interface:ClientAdds a listener that will be notified when any message or object is received from the server.- Specified by:
addMessageListenerin interfaceClient- Parameters:
listener- the listener to add
-
addMessageListener
Description copied from interface:ClientAdds a listener that will be notified when messages of the specified types are received.- Specified by:
addMessageListenerin interfaceClient- Parameters:
listener- the listener to addclasses- the message classes the listener should receive
-
removeMessageListener
Description copied from interface:ClientRemoves a previously registered wildcard listener. This does not remove this listener from any type-specific registrations.- Specified by:
removeMessageListenerin interfaceClient- Parameters:
listener- the listener to remove
-
removeMessageListener
Description copied from interface:ClientRemoves a previously registered type-specific listener from the specified types.- Specified by:
removeMessageListenerin interfaceClient- Parameters:
listener- the listener to removeclasses- the message classes to unregister
-
addErrorListener
Description copied from interface:ClientAdds a listener that will be notified when any connection errors occur. If a client has no error listeners then the default behavior is to close the connection and provide an appropriate DisconnectInfo to any ClientStateListeners. If the application adds its own error listeners then it must take care of closing the connection itself.- Specified by:
addErrorListenerin interfaceClient- Parameters:
listener- the listener to add
-
removeErrorListener
Description copied from interface:ClientRemoves a previously registered error listener.- Specified by:
removeErrorListenerin interfaceClient- Parameters:
listener- the listener to remove
-
fireConnected
protected void fireConnected()Notifies registered state listeners that the client connected. -
startServices
protected void startServices()Starts the client services after connection setup completes. -
fireDisconnected
Notifies registered state listeners that the client disconnected.- Parameters:
info- optional disconnect information
-
handleError
Either calls the ErrorListener or closes the connection if there are no listeners.- Parameters:
t- the error to handle
-
configureChannels
protected void configureChannels(long tempId, int[] ports) Configures any additional channels announced by the server.- Parameters:
tempId- the temporary client registration idports- the alternate channel ports announced by the server
-
dispatch
Dispatches a received message, handling connection-management messages internally.- Parameters:
m- the received message
-