Package com.jme3.network.base
Class DefaultClient
java.lang.Object
com.jme3.network.base.DefaultClient
- All Implemented Interfaces:
Client
,MessageConnection
- Direct Known Subclasses:
Network.NetworkClientImpl
A default implementation of the Client interface that delegates
its network connectivity to a kernel.Connector.
-
Nested Class Summary
-
Field Summary
Fields inherited from interface com.jme3.network.MessageConnection
CHANNEL_DEFAULT_RELIABLE, CHANNEL_DEFAULT_UNRELIABLE
-
Constructor Summary
ConstructorDescriptionDefaultClient
(String gameName, int version) DefaultClient
(String gameName, int version, Connector reliable, Connector fast, ConnectorFactory connectorFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClientStateListener
(ClientStateListener listener) Adds a listener that will be notified about connection state changes.void
addErrorListener
(ErrorListener<? super Client> listener) Adds a listener that will be notified when any connection errors occur.void
addMessageListener
(MessageListener<? super Client> listener) Adds a listener that will be notified when any message or object is received from the server.void
addMessageListener
(MessageListener<? super Client> listener, Class... classes) Adds a listener that will be notified when messages of the specified types are received.protected void
protected void
void
close()
Closes this connection to the server.protected void
protected void
configureChannels
(long tempId, int[] ports) protected void
protected void
protected void
Returns the 'game name' for servers to which this client should be able to connect.int
getId()
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.int
Returns the game-specific version of the server this client should be able to connect to.protected void
Either calls the ErrorListener or closes the connection if there are no listeners.boolean
Returns true if this client is fully connected to the host.boolean
Returns true if this client has been started and is still running.void
removeClientStateListener
(ClientStateListener listener) Removes a previously registered connection listener.void
removeErrorListener
(ErrorListener<? super Client> listener) Removes a previously registered error listener.void
removeMessageListener
(MessageListener<? super Client> listener) Removes a previously registered wildcard listener.void
removeMessageListener
(MessageListener<? super Client> listener, Class... classes) Removes a previously registered type-specific listener from the specified types.void
Sends a message to the other end of the connection using the specified alternate channel.protected void
void
Sends a message to the server.protected void
setPrimaryConnectors
(Connector reliable, Connector fast, ConnectorFactory connectorFactory) void
start()
Starts the client allowing it to begin processing incoming messages and delivering them to listeners.protected void
protected void
-
Constructor Details
-
DefaultClient
-
DefaultClient
public DefaultClient(String gameName, int version, Connector reliable, Connector fast, ConnectorFactory connectorFactory)
-
-
Method Details
-
addStandardServices
protected void addStandardServices() -
setPrimaryConnectors
protected void setPrimaryConnectors(Connector reliable, Connector fast, ConnectorFactory connectorFactory) -
checkRunning
protected void checkRunning() -
start
public void start()Description copied from interface:Client
Starts the client allowing it to begin processing incoming messages and delivering them to listeners. -
isStarted
public boolean isStarted()Description copied from interface:Client
Returns true if this client has been started and is still running. -
waitForConnected
protected void waitForConnected() -
isConnected
public boolean isConnected()Description copied from interface:Client
Returns true if this client is fully connected to the host.- Specified by:
isConnected
in interfaceClient
-
getId
public int getId()Description copied from interface:Client
Returns a unique ID for this client within the remote server or -1 if this client isn't fully connected to the server. -
getGameName
Description copied from interface:Client
Returns 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:
getGameName
in interfaceClient
-
getVersion
public int getVersion()Description copied from interface:Client
Returns the game-specific version of the server this client should be able to connect to.- Specified by:
getVersion
in interfaceClient
-
getServices
Description copied from interface:Client
Returns the manager for client services. Client services extend the functionality of the client.- Specified by:
getServices
in interfaceClient
-
send
Description copied from interface:Client
Sends a message to the server.- Specified by:
send
in interfaceClient
- Specified by:
send
in interfaceMessageConnection
-
send
Description copied from interface:Client
Sends a message to the other end of the connection using the specified alternate channel.- Specified by:
send
in interfaceClient
- Specified by:
send
in interfaceMessageConnection
-
send
-
close
public void close()Description copied from interface:Client
Closes this connection to the server. -
closeConnections
-
addClientStateListener
Description copied from interface:Client
Adds a listener that will be notified about connection state changes.- Specified by:
addClientStateListener
in interfaceClient
-
removeClientStateListener
Description copied from interface:Client
Removes a previously registered connection listener.- Specified by:
removeClientStateListener
in interfaceClient
-
addMessageListener
Description copied from interface:Client
Adds a listener that will be notified when any message or object is received from the server.- Specified by:
addMessageListener
in interfaceClient
-
addMessageListener
Description copied from interface:Client
Adds a listener that will be notified when messages of the specified types are received.- Specified by:
addMessageListener
in interfaceClient
-
removeMessageListener
Description copied from interface:Client
Removes a previously registered wildcard listener. This does not remove this listener from any type-specific registrations.- Specified by:
removeMessageListener
in interfaceClient
-
removeMessageListener
Description copied from interface:Client
Removes a previously registered type-specific listener from the specified types.- Specified by:
removeMessageListener
in interfaceClient
-
addErrorListener
Description copied from interface:Client
Adds 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:
addErrorListener
in interfaceClient
-
removeErrorListener
Description copied from interface:Client
Removes a previously registered error listener.- Specified by:
removeErrorListener
in interfaceClient
-
fireConnected
protected void fireConnected() -
startServices
protected void startServices() -
fireDisconnected
-
handleError
Either calls the ErrorListener or closes the connection if there are no listeners. -
configureChannels
protected void configureChannels(long tempId, int[] ports) -
dispatch
-