com.jme3.network.base
Class DefaultClient

java.lang.Object
  extended by com.jme3.network.base.DefaultClient
All Implemented Interfaces:
Client, MessageConnection
Direct Known Subclasses:
Network.NetworkClientImpl

public class DefaultClient
extends java.lang.Object
implements Client

A default implementation of the Client interface that delegates its network connectivity to a kernel.Connector.


Nested Class Summary
protected  class DefaultClient.Redispatch
           
 
Constructor Summary
DefaultClient(java.lang.String gameName, int version)
           
DefaultClient(java.lang.String gameName, int version, Connector reliable, Connector fast, ConnectorFactory connectorFactory)
           
 
Method Summary
 void 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, java.lang.Class... classes)
          Adds a listener that will be notified when messages of the specified types are received.
protected  void checkRunning()
           
 void close()
          Closes this connection to the server.
protected  void closeConnections(ClientStateListener.DisconnectInfo info)
           
protected  void configureChannels(long tempId, int[] ports)
           
protected  void dispatch(Message m)
           
protected  void fireConnected()
           
protected  void fireDisconnected(ClientStateListener.DisconnectInfo info)
           
 java.lang.String getGameName()
          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.
 int getVersion()
          Returns the game-specific version of the server this client should be able to connect to.
protected  void handleError(java.lang.Throwable t)
          Either calls the ErrorListener or closes the connection if there are no listeners.
 boolean isConnected()
          Returns true if this client is fully connected to the host.
 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, java.lang.Class... classes)
          Removes a previously registered type-specific listener from the specified types.
 void send(int channel, Message message)
          Sends a message to the other end of the connection using the specified alternate channel.
protected  void send(int channel, Message message, boolean waitForConnected)
           
 void send(Message message)
          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 waitForConnected()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultClient

public DefaultClient(java.lang.String gameName,
                     int version)

DefaultClient

public DefaultClient(java.lang.String gameName,
                     int version,
                     Connector reliable,
                     Connector fast,
                     ConnectorFactory connectorFactory)
Method Detail

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.

Specified by:
start in interface Client

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 interface Client

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.

Specified by:
getId in interface Client

getGameName

public java.lang.String 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 interface Client

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 interface Client

send

public void send(Message message)
Description copied from interface: Client
Sends a message to the server.

Specified by:
send in interface Client
Specified by:
send in interface MessageConnection

send

public void send(int channel,
                 Message message)
Description copied from interface: Client
Sends a message to the other end of the connection using the specified alternate channel.

Specified by:
send in interface Client
Specified by:
send in interface MessageConnection

send

protected void send(int channel,
                    Message message,
                    boolean waitForConnected)

close

public void close()
Description copied from interface: Client
Closes this connection to the server.

Specified by:
close in interface Client

closeConnections

protected void closeConnections(ClientStateListener.DisconnectInfo info)

addClientStateListener

public void addClientStateListener(ClientStateListener listener)
Description copied from interface: Client
Adds a listener that will be notified about connection state changes.

Specified by:
addClientStateListener in interface Client

removeClientStateListener

public void removeClientStateListener(ClientStateListener listener)
Description copied from interface: Client
Removes a previously registered connection listener.

Specified by:
removeClientStateListener in interface Client

addMessageListener

public void addMessageListener(MessageListener<? super Client> listener)
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 interface Client

addMessageListener

public void addMessageListener(MessageListener<? super Client> listener,
                               java.lang.Class... classes)
Description copied from interface: Client
Adds a listener that will be notified when messages of the specified types are received.

Specified by:
addMessageListener in interface Client

removeMessageListener

public void removeMessageListener(MessageListener<? super Client> listener)
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 interface Client

removeMessageListener

public void removeMessageListener(MessageListener<? super Client> listener,
                                  java.lang.Class... classes)
Description copied from interface: Client
Removes a previously registered type-specific listener from the specified types.

Specified by:
removeMessageListener in interface Client

addErrorListener

public void addErrorListener(ErrorListener<? super Client> listener)
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 interface Client

removeErrorListener

public void removeErrorListener(ErrorListener<? super Client> listener)
Description copied from interface: Client
Removes a previously registered error listener.

Specified by:
removeErrorListener in interface Client

fireConnected

protected void fireConnected()

fireDisconnected

protected void fireDisconnected(ClientStateListener.DisconnectInfo info)

handleError

protected void handleError(java.lang.Throwable t)
Either calls the ErrorListener or closes the connection if there are no listeners.


configureChannels

protected void configureChannels(long tempId,
                                 int[] ports)

dispatch

protected void dispatch(Message m)