inf1010.pusle.chat.server
Class ChatServer

java.lang.Object
  extended by inf1010.pusle.chat.server.ChatServer
All Implemented Interfaces:
java.lang.Runnable

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

A simple chat server capable of serving multiple clients.


Constructor Summary
ChatServer(int port)
          Creates a ChatServer binding a ServerSocket to the given port.
 
Method Summary
 void broadcast(java.lang.String msg, inf1010.pusle.chat.server.Client sender)
          Sends a chat message on the network.
static void main(java.lang.String[] args)
          Entry point.
 void removeClient(inf1010.pusle.chat.server.Client c)
          Disconnects a client and removes it from the list of clients.
 void run()
          Wait for client connections and add them to the list of clients.
 void sendMessage(java.lang.String msg, inf1010.pusle.chat.server.Client c)
          Send message to other connected clients.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatServer

public ChatServer(int port)
Creates a ChatServer binding a ServerSocket to the given port.

Parameters:
port - the port to bind the server socket to.
Method Detail

main

public static void main(java.lang.String[] args)
Entry point.

Parameters:
args - The first argument is the port, the rest are ignored.

removeClient

public void removeClient(inf1010.pusle.chat.server.Client c)
Disconnects a client and removes it from the list of clients.

Parameters:
c - the client to remove.

broadcast

public void broadcast(java.lang.String msg,
                      inf1010.pusle.chat.server.Client sender)
Sends a chat message on the network.

Parameters:
msg - the message to be sent.
sender - the client sending the message.

sendMessage

public void sendMessage(java.lang.String msg,
                        inf1010.pusle.chat.server.Client c)
Send message to other connected clients.

Parameters:
msg - the message to send to the clients.
c - the client sending the message.

run

public void run()
Wait for client connections and add them to the list of clients.

Specified by:
run in interface java.lang.Runnable