Class ChatRoomServer

java.lang.Object
  |
  +--ChatRoomServer
All Implemented Interfaces:
java.lang.Runnable

public class ChatRoomServer
extends java.lang.Object
implements java.lang.Runnable

A Chat Room Server that handles up to 50 user simultaneously in the room.


Constructor Summary
ChatRoomServer()
          Constructs a new ChatRoomServer on port 9090.
ChatRoomServer(int serverPort)
          Constructs a new ChatRoomServer on a specific port.
 
Method Summary
 java.util.Vector getConnections()
          Returns the current server connections.
 int getNumberOfConnections()
          Returns the number of online connections.
 void handleDisconnection(ChatRoomConnection connection)
          handles the disconnection of a user.
 boolean isConnected()
          Returns true if the server is connected; false otherwise.
 void logError(java.lang.String message)
          logs an Error to the Server log.
 void logMessage(java.lang.String message)
          logs a message to the Server log.
 void run()
          Runs this thread
 void sendToAllUsers(java.lang.String message)
          Sends the given message to all the connected users
 void setLogger(ChatRoomServerUI log)
          Sets the logger of this server
 void start()
          Starts the server
 void stop()
          Stops the server
 void updateUI()
          Called to update the ui whenever the connections of the server has changed (added or removed connections)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatRoomServer

public ChatRoomServer()
Constructs a new ChatRoomServer on port 9090.


ChatRoomServer

public ChatRoomServer(int serverPort)
Constructs a new ChatRoomServer on a specific port.

Method Detail

start

public void start()
Starts the server


stop

public void stop()
Stops the server


isConnected

public boolean isConnected()
Returns true if the server is connected; false otherwise.


setLogger

public void setLogger(ChatRoomServerUI log)
Sets the logger of this server

Parameters:
log - The ChatRoomServerUI logger

getConnections

public java.util.Vector getConnections()
Returns the current server connections.

Returns:
A Vector of connections

getNumberOfConnections

public int getNumberOfConnections()
Returns the number of online connections.

Returns:
The current number of online users

run

public void run()
Runs this thread

Specified by:
run in interface java.lang.Runnable

handleDisconnection

public void handleDisconnection(ChatRoomConnection connection)
                         throws java.io.IOException
handles the disconnection of a user. notify the waiting connections that are waiting.

java.io.IOException

sendToAllUsers

public void sendToAllUsers(java.lang.String message)
                    throws java.io.IOException
Sends the given message to all the connected users

java.io.IOException

logMessage

public void logMessage(java.lang.String message)
logs a message to the Server log.

Parameters:
message - The message to log.

logError

public void logError(java.lang.String message)
logs an Error to the Server log.

Parameters:
message - The message to log.

updateUI

public void updateUI()
Called to update the ui whenever the connections of the server has changed (added or removed connections)