123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Net;
- using websocketserver.Library;
- using System.Configuration;
- namespace websocketserver
- {
- class Program
- {
- static void Main(string[] args)
- {
- int port = 8080;
- var config = new ConfigurationLoader();
- try
- {
- config.Load();
- port = int.Parse(config.GetProperty("websocket-server.port").ToString());
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine($"WebSocket server port: {port}");
- var server = new ChatServer(IPAddress.Any, port);
- Console.Write("Server starting...");
- server.Start();
- Console.WriteLine(" Done!");
- Console.WriteLine("Commands: ");
- Console.WriteLine("\tquit: stops the server");
- Console.WriteLine("\trestart: restarts the server");
- for (;;)
- {
- string line = Console.ReadLine();
- if (string.IsNullOrEmpty(line)) {
- continue;
- }
- if (line == "quit" || line == "exit")
- {
- break;
- }
- if (line == "restart")
- {
- //TODO: broadcast to all users a disconnect
- Console.Write("Server restarting...");
- server.Restart();
- Console.WriteLine(" Done!");
- continue;
- }
- line = "(admin) " + line;
- server.MulticastText(line);
- Console.WriteLine(line);
- }
- Console.Write("Server stopping...");
- server.Stop();
- Console.WriteLine("Done!");
- }
- }
- }
|