Class ChatRoomConnection

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

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

A ChatRoomConnection is a single connection between the server and a chat room client. The Chat Room Connection encapsulates the communication between the client and the server, which can be executed on a seperate thread


Constructor Summary
ChatRoomConnection(java.net.Socket socket, ChatRoomServer server)
          Constructs a new ChatRoomConnection on the given socket.
 
Method Summary
 void close()
          Closes this connection by closing the streams and the connections socket
 java.lang.String getHostAddress()
          Returns the hostAddress for this connection
 java.lang.String getHostName()
          Returns the hostName of this connection.
 ChatRoomServer getServer()
          Returns the Chat Room Server.
 java.lang.String getUserName()
          Returns the client user name for this connection
 void run()
          Executes the task of this connection object
 void sendMessage(java.lang.String message)
          Sends the given message through the connections output stream.
 void setUserName(java.lang.String userName)
          Set the User name of this connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatRoomConnection

public ChatRoomConnection(java.net.Socket socket,
                          ChatRoomServer server)
Constructs a new ChatRoomConnection on the given socket.

Parameters:
socket - the socket of the connection.
server - the server that serves this connection
Method Detail

getHostName

public java.lang.String getHostName()
Returns the hostName of this connection.


getHostAddress

public java.lang.String getHostAddress()
Returns the hostAddress for this connection


getUserName

public java.lang.String getUserName()
Returns the client user name for this connection


setUserName

public void setUserName(java.lang.String userName)
Set the User name of this connection

Parameters:
userName - the user name

getServer

public ChatRoomServer getServer()
Returns the Chat Room Server.

Returns:
the ChatRoomServer that serves this Connection

run

public void run()
Executes the task of this connection object

Specified by:
run in interface java.lang.Runnable

sendMessage

public void sendMessage(java.lang.String message)
                 throws java.io.IOException
Sends the given message through the connections output stream.

Parameters:
message - a message to send.
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes this connection by closing the streams and the connections socket

java.io.IOException