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
{
    private static PiriServerData serverData = new PiriServerData();

    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);
        StackTraceElement[] ste = e.getStackTrace();
        for(int i=0; i<ste.length; i++)
            System.out.println(ste[i]);
        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
        serverData.createConnection(pSocket);
    }

    public static void dataRecieved(Connection pConnection, Command pCommand) throws PiriException, IOException
    {
        // Called whenever the server recieves data from the client
        // Send data to be processed
//        try
//        {
//            PiriServerData.dataRecieved(pConnectn, pCommand);
//        }
//        catch(PiriException e)//, IOException e)
//        {
//            fatalError(e);
//        }
    }
}
