Example #1
0
    static void Main(string[] args)
    {
        SocketHandler.Server servSocket = new SocketHandler.Server(PORT);
        udpServer = new SocketHandler.UDPServer(PORT);
        servSocket.onNewConnection += StartNewSession;

        bool running = true;

        servSocket.onCloseConnection += (e) =>
        {
            if (e != null)
            {
                Console.WriteLine("Server crashed:");
                Console.WriteLine(e);
                running = false;
            }
        };

        Console.WriteLine();
        Console.WriteLine(HELP_MESSAGE);

        string message;

        while (running)
        {
            message = Console.ReadLine();
            switch (message)
            {
            case "q":
            case "quit":
                running = false;
                break;

            case "h":
            case "help":
                Console.WriteLine(HELP_MESSAGE);
                break;

            case "live":
                Console.WriteLine(users.Count);
                break;

            case "dnstest":
                Console.WriteLine("" + Dns.GetHostAddresses(DNS)[0]);
                break;

            default:
                Console.WriteLine(message + " is not a valid command");
                break;
            }
        }

        for (int i = 0; i < users.Count; ++i)
        {
            users[i].LogOut();
        }
        servSocket.Stop();
        udpServer.Stop();
    }
Example #2
0
 public User(Socket socket, SocketHandler.UDPServer udpServer)
 {
     this.udpServer = udpServer;
     endpoint       = (IPEndPoint)socket.RemoteEndPoint;
     controller     = new SocketHandler.Controller(socket);
     controller.onCloseConnection += (e) => Server.LogOut(e, this);
     controller.onReceiveData     += (s) => Server.ProcessMessage(s, this);
 }