Interface Client
- All Superinterfaces:
MessageConnection
- All Known Subinterfaces:
NetworkClient
- All Known Implementing Classes:
DefaultClient, Network.NetworkClientImpl
Represents a remote connection to a server that can be used
for sending and receiving messages.
- Author:
- Paul Speed
-
Field Summary
Fields inherited from interface MessageConnection
CHANNEL_DEFAULT_RELIABLE, CHANNEL_DEFAULT_UNRELIABLE -
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.voidclose()Closes this connection to the server.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.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.voidSends a message to the server.voidstart()Starts the client allowing it to begin processing incoming messages and delivering them to listeners.
-
Method Details
-
start
void start()Starts the client allowing it to begin processing incoming messages and delivering them to listeners. -
isConnected
boolean isConnected()Returns true if this client is fully connected to the host.- Returns:
- true if the client is connected to the server
-
isStarted
boolean isStarted()Returns true if this client has been started and is still running.- Returns:
- true if the client has been started and not yet closed
-
getId
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 server-assigned client id, or -1 if not connected
-
getGameName
String getGameName()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.- Returns:
- the configured game name
-
getVersion
int getVersion()Returns the game-specific version of the server this client should be able to connect to.- Returns:
- the expected game protocol version
-
getServices
ClientServiceManager getServices()Returns the manager for client services. Client services extend the functionality of the client.- Returns:
- the client service manager
-
send
Sends a message to the server.- Specified by:
sendin interfaceMessageConnection- Parameters:
message- the message to send
-
send
Sends a message to the other end of the connection using the specified alternate channel.- Specified by:
sendin interfaceMessageConnection- Parameters:
channel- the transport channel to usemessage- the message to send
-
close
void close()Closes this connection to the server. -
addClientStateListener
Adds a listener that will be notified about connection state changes.- Parameters:
listener- the listener to add
-
removeClientStateListener
Removes a previously registered connection listener.- Parameters:
listener- the listener to remove
-
addMessageListener
Adds a listener that will be notified when any message or object is received from the server.- Parameters:
listener- the listener to add
-
addMessageListener
Adds a listener that will be notified when messages of the specified types are received.- Parameters:
listener- the listener to addclasses- the message classes the listener should receive
-
removeMessageListener
Removes a previously registered wildcard listener. This does not remove this listener from any type-specific registrations.- Parameters:
listener- the listener to remove
-
removeMessageListener
Removes a previously registered type-specific listener from the specified types.- Parameters:
listener- the listener to removeclasses- the message classes to unregister
-
addErrorListener
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.- Parameters:
listener- the listener to add
-
removeErrorListener
Removes a previously registered error listener.- Parameters:
listener- the listener to remove
-