dd.net
Interface Client

All Known Implementing Classes:
NetClient

public interface Client

Interface to network client and servers. This is the interface that the networking layer (client and server) must support. Rather than talk to the implementation and network-transport specific networking layer, it is advisable for all communication with the network be handled through this interface. This provides a basic interface for what network objects must support; starting/stopping, sending messages, and handling incoming messages.

Author:
Eric Scharff

Method Summary
 java.lang.String getClientName()
           
 java.io.BufferedReader getReader()
          Returns the reader associated with the networking layer.
 void handleMessage(java.lang.String message)
          Handle an incoming network message.
 void sendMessage(java.lang.String message)
          Send an outgoing network message.
 void setClientName(java.lang.String name)
           
 void setGame(GameServer g)
           
 void startRunning()
          Begin operating of the client.
 void stopRunning()
          Ends operation of the client.
 

Method Detail

startRunning

public void startRunning()
Begin operating of the client. This method may start an additional thread which handles incoming or outgoing network connections. This method should be called once in order to begin the client's operation.


stopRunning

public void stopRunning()
Ends operation of the client. This method will terminate any network connections or other server handling, and should clean up any used resources. This method may abruptly terminate the client or server, so it is advistable to avoid using this call and instead rely on a message that handles a clean disconnection.


handleMessage

public void handleMessage(java.lang.String message)
Handle an incoming network message. Messages are typically one-line strings with a command name and arguments. The networking client will typically handle the message by looking at the command name and calling an appropriate handler, although the precise action taken when a message is received is up to the client. This method is called internally by the networking layer and is rarely called outside of the network code.

Parameters:
message - the message that was received from the network
See Also:
Handler

sendMessage

public void sendMessage(java.lang.String message)
Send an outgoing network message. Messages are typically one-line strings with a command name and arguments. This method is used to send an outgoing message to the client or server, and is the main low-level interface for generating outgoing network traffic.

Although this interface is called the Client, both clients and servers can send messages. The semantics of this vary. Calling this method from a client sends a message to the server. On the server, this method is used to send a message back to a specific client.

Parameters:
message - the message that should be sent to the network

getReader

public java.io.BufferedReader getReader()
Returns the reader associated with the networking layer. The incoming command stream is a series of textual lines. For commands that span multiple lines, this method can be used to acquire the input after the message line. This reader will be pointing to the line after the current message line when handleMessage(java.lang.String) is called.

Do not close this stream. It is shared by all of the networking clients and will be disposed within the networking support code.

This reader may block if no input is available. Great care should be used when using this method. Use single-line commands whenever possible.

Returns:
the line-oriented character stream associated with this client

getClientName

public java.lang.String getClientName()

setClientName

public void setClientName(java.lang.String name)

setGame

public void setGame(GameServer g)