package apz.pirichat.server;
import java.net.Socket;
import apz.pirichat.shared.PiriException;
import apz.pirichat.shared.ChatMessage;
import java.io.IOException;

public class PiriServer
{
    public static void main(String[] args)
    {
        // Create our listening thread
        Thread listenThread = new ListenThread(9999);
        // Activate it
        listenThread.start();
    }

    public static void fatalError(Exception e)
    {
        // This is called whenever any of our threads has a fatal error
        // Display error and exit program
        System.out.println(e);
        System.exit(1);
    }

    public static void acceptConnection(Socket pSocket)
    {
        // This is called whenever a connection is recieved
        // Create and run a new client thread for this socket
        ClientThread clientThread = new ClientThread(pSocket);
        clientThread.start();
    }

    public static void dataRecieved(ClientThread pClientThread, ChatMessage pChatMessage) throws PiriException, IOException
    {
        // Called whenever the server recieves data from the client
        System.out.println(pChatMessage);


        PiriServerData.initialise(pClientThread);

    }
}
