Class ChatRoomProtocol

java.lang.Object
  |
  +--ChatRoomProtocol

public class ChatRoomProtocol
extends java.lang.Object

A Server-Client Protocol for a ChatRoom.


Field Summary
static int CHAT_ROOM_MESSAGE
           
static int REQUESTING_CONNECTION
           
static int SEND_USER_NAME
           
static int USER_DISCONNECTING
           
static int USER_NAME
           
static int WELCOME_MESSAGE
           
 
Method Summary
 java.lang.String createChatMessage(java.lang.String message)
          Creates a regular chat message in the form of: ID message...
 java.lang.String createConnectionRequest()
          Creates a connection Message for a chat room client to send to it's server
 java.lang.String createDisconnectionRequest(java.lang.String userName)
          Creates a chat client disconnection request message.
 java.lang.String createUserNameResponse(java.lang.String userName)
          Creates a chat User-Name response message.
static ChatRoomProtocol getInstance()
          Used to access the single protocol instance
 void handleClientMessage(java.lang.String message, ChatRoomConnection connection)
          Handles a message received from the client on a given chat room connection.
 void handleServerMessage(java.lang.String message, ChatRoomClient client)
          Handles a message received from the server to a given client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUESTING_CONNECTION

public static final int REQUESTING_CONNECTION
See Also:
Constant Field Values

SEND_USER_NAME

public static final int SEND_USER_NAME
See Also:
Constant Field Values

USER_NAME

public static final int USER_NAME
See Also:
Constant Field Values

USER_DISCONNECTING

public static final int USER_DISCONNECTING
See Also:
Constant Field Values

CHAT_ROOM_MESSAGE

public static final int CHAT_ROOM_MESSAGE
See Also:
Constant Field Values

WELCOME_MESSAGE

public static final int WELCOME_MESSAGE
See Also:
Constant Field Values
Method Detail

getInstance

public static ChatRoomProtocol getInstance()
Used to access the single protocol instance


createConnectionRequest

public java.lang.String createConnectionRequest()
Creates a connection Message for a chat room client to send to it's server


createDisconnectionRequest

public java.lang.String createDisconnectionRequest(java.lang.String userName)
Creates a chat client disconnection request message.

Returns:
A disconnection request string

createUserNameResponse

public java.lang.String createUserNameResponse(java.lang.String userName)
Creates a chat User-Name response message.

Parameters:
userName - the user name
Returns:
A user-name response string

createChatMessage

public java.lang.String createChatMessage(java.lang.String message)
Creates a regular chat message in the form of: ID message... The ID is the message type constant.

Parameters:
message - the content of the message
Returns:
A string of a regular chat message

handleClientMessage

public void handleClientMessage(java.lang.String message,
                                ChatRoomConnection connection)
                         throws java.io.IOException
Handles a message received from the client on a given chat room connection.

Parameters:
message - the client's message.
connection - the ChatRoomConnection of that client.
java.io.IOException

handleServerMessage

public void handleServerMessage(java.lang.String message,
                                ChatRoomClient client)
                         throws java.io.IOException,
                                java.net.ProtocolException
Handles a message received from the server to a given client.

Parameters:
message - the server's message
client - the ChatRoomClient to communicate with.
java.io.IOException
java.net.ProtocolException