Beispiel #1
0
        static void Main(string[] args)
        {
            db = new DB("chat");

            server = new WSServer(25566);
            server.StartListening();

            while (true)
            {
                Console.Write("Enter command (c/clear, q/quit, l/list, t/talk): ");

                string cmd = Console.ReadLine();
                string s   = cmd.ToLower();

                if (s.Equals("c") || s.Equals("clear"))
                {
                    db.wipe();
                }
                else if (s.Equals("q") || s.Equals("quit"))
                {
                    break;
                }
                else if (s.Equals("l") || s.Equals("list"))
                {
                    List <string> names = server.getAllNicknames();
                    foreach (string n in names)
                    {
                        Console.WriteLine(n);
                    }
                }
                else if (s.StartsWith("t "))
                {
                    string msg = cmd.Substring(2, cmd.Length - 2);
                    if (msg.StartsWith("[") || msg.StartsWith("!"))
                    {
                        msg = ' ' + msg;
                    }
                    server.Broadcast(msg);
                }
                else if (s.StartsWith("talk "))
                {
                    string msg = cmd.Substring(5, cmd.Length - 5);
                    if (msg.StartsWith("[") || msg.StartsWith("!"))
                    {
                        msg = ' ' + msg;
                    }
                    server.Broadcast(msg);
                }
                else
                {
                    Console.WriteLine("Unrecognised command");
                }
            }

            db.close();
        }
Beispiel #2
0
        /// <summary>
        /// Initialize the application and start the Alchemy Websockets server
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Initialize the server on port 81, accept any IPs, and bind events.
            WSServer AServer = new WSServer(81, IPAddress.Any);

            AServer.DefaultOnReceive    = new OnEventDelegate(OnReceive);
            AServer.DefaultOnSend       = new OnEventDelegate(OnSend);
            AServer.DefaultOnConnect    = new OnEventDelegate(OnConnect);
            AServer.DefaultOnDisconnect = new OnEventDelegate(OnDisconnect);
            AServer.TimeOut             = new TimeSpan(0, 5, 0);

            AServer.Start();

            // Accept commands on the console and keep it alive
            string Command = string.Empty;

            while (Command != "exit")
            {
                Command = Console.ReadLine();
            }

            AServer.Stop();
        }