public class DefaultClient extends java.lang.Object implements Client
| Modifier and Type | Class and Description |
|---|---|
protected class |
DefaultClient.Redispatch |
CHANNEL_DEFAULT_RELIABLE, CHANNEL_DEFAULT_UNRELIABLE| Constructor and Description |
|---|
DefaultClient(java.lang.String gameName,
int version) |
DefaultClient(java.lang.String gameName,
int version,
Connector reliable,
Connector fast,
ConnectorFactory connectorFactory) |
| Modifier and Type | Method and Description |
|---|---|
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 |
addStandardServices() |
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.
|
ClientServiceManager |
getServices()
Returns the manager for client services.
|
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.
|
boolean |
isStarted()
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,
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 |
startServices() |
protected void |
waitForConnected() |
public DefaultClient(java.lang.String gameName,
int version)
public DefaultClient(java.lang.String gameName,
int version,
Connector reliable,
Connector fast,
ConnectorFactory connectorFactory)
protected void addStandardServices()
protected void setPrimaryConnectors(Connector reliable, Connector fast, ConnectorFactory connectorFactory)
protected void checkRunning()
public void start()
Clientpublic boolean isStarted()
Clientprotected void waitForConnected()
public boolean isConnected()
ClientisConnected in interface Clientpublic int getId()
Clientpublic java.lang.String getGameName()
ClientgetGameName in interface Clientpublic int getVersion()
ClientgetVersion in interface Clientpublic ClientServiceManager getServices()
ClientgetServices in interface Clientpublic void send(Message message)
Clientsend in interface Clientsend in interface MessageConnectionpublic void send(int channel,
Message message)
Clientsend in interface Clientsend in interface MessageConnectionprotected void send(int channel,
Message message,
boolean waitForConnected)
public void close()
Clientprotected void closeConnections(ClientStateListener.DisconnectInfo info)
public void addClientStateListener(ClientStateListener listener)
ClientaddClientStateListener in interface Clientpublic void removeClientStateListener(ClientStateListener listener)
ClientremoveClientStateListener in interface Clientpublic void addMessageListener(MessageListener<? super Client> listener)
ClientaddMessageListener in interface Clientpublic void addMessageListener(MessageListener<? super Client> listener, java.lang.Class... classes)
ClientaddMessageListener in interface Clientpublic void removeMessageListener(MessageListener<? super Client> listener)
ClientremoveMessageListener in interface Clientpublic void removeMessageListener(MessageListener<? super Client> listener, java.lang.Class... classes)
ClientremoveMessageListener in interface Clientpublic void addErrorListener(ErrorListener<? super Client> listener)
ClientaddErrorListener in interface Clientpublic void removeErrorListener(ErrorListener<? super Client> listener)
ClientremoveErrorListener in interface Clientprotected void fireConnected()
protected void startServices()
protected void fireDisconnected(ClientStateListener.DisconnectInfo info)
protected void handleError(java.lang.Throwable t)
protected void configureChannels(long tempId,
int[] ports)
protected void dispatch(Message m)