main
Class Server

java.lang.Object
  extended by main.Server

public class Server
extends java.lang.Object

Chat server runner.


Field Summary
 java.util.Hashtable<java.lang.Integer,Conversation> convTable
           
 java.util.Hashtable<java.lang.String,User> userTable
           
 
Constructor Summary
Server(int port)
          Creates a new instance of a server.
 
Method Summary
 void freeID(int ID)
          Frees an ID that was previously reserved for a conversation, that way they can be reused without restarting the server.
static void main(java.lang.String[] args)
          Start a chat server.
 int newID()
          Generates a new, random ID for a conversation.
 void serve()
          Waits for clients to connects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userTable

public final java.util.Hashtable<java.lang.String,User> userTable

convTable

public final java.util.Hashtable<java.lang.Integer,Conversation> convTable
Constructor Detail

Server

public Server(int port)
       throws java.io.IOException
Creates a new instance of a server.

Parameters:
port - Port to listen to clients on
Throws:
java.io.IOException - if a Server Socket cannot be made on the port
Method Detail

serve

public void serve()
Waits for clients to connects. Upon connecting, a new thread is generated. If there is an error, it ignores it and waits for the next client one to connect.


newID

public int newID()
Generates a new, random ID for a conversation. Checks to ensure that the ID has not been taken. It is randomly generated as a 32 bit signed int.

Returns:
random conversation ID as an integer

freeID

public void freeID(int ID)
Frees an ID that was previously reserved for a conversation, that way they can be reused without restarting the server.

Parameters:
ID - integer ID to free from the list of currently used ID's

main

public static void main(java.lang.String[] args)
Start a chat server.