Exemplo n.º 1
0
        /// <summary>
        /// Method responsible for start the server.
        /// </summary>
        public static void StartServer()
        {
            _server = new KingServer();
            _server.OnMessageReceivedHandler = OnMessageReceived;

            new Thread(() =>
            {
                _stopwatch = Stopwatch.StartNew();

                while (true)
                {
                    Thread.Sleep(1000 / _serverFrequency);

                    if (_stopwatch.ElapsedMilliseconds > 1000 * 10)
                    {
                        Console.WriteLine(string.Format("Server in={0} ({1} KB/s)  out={0} ({1} KB/s)", _messagesReceived, (_dataReceived * 1000 / (_stopwatch.ElapsedMilliseconds * 1024))));
                        _stopwatch.Stop();
                        _stopwatch        = Stopwatch.StartNew();
                        _messagesReceived = 0;
                        _dataReceived     = 0;
                    }
                }
            }).Start();

            _server.Start();
        }
Exemplo n.º 2
0
        public ServerManager(NetworkListenerType type)
        {
            _serverTread = new Thread(() =>
            {
                KingServer = new KingServer();
                KingServer.Start(type);
            });

            _serverTread.Start();
        }
Exemplo n.º 3
0
 /// <summary>
 /// This method is responsible for run the server.
 /// </summary>
 public void Run()
 {
     try
     {
         _server = new KingServer();
         _server.OnMessageReceivedHandler = OnMessageReceived;
         _server.Start();
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}");
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// This method is responsible for main execution of console application.
        /// </summary>
        /// <param name="args">The string args received by parameters.</param>
        static void Main(string[] args)
        {
            try
            {
                var server = new KingServer();
                server.PutHandler <MyPacketHandlerOne, MyPackets>(MyPackets.PacketOne);
                server.Start();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method is responsible for main execution of console application.
        /// </summary>
        /// <param name="args">The string args received by parameters.</param>
        static void Main(string[] args)
        {
            try
            {
                var server = new KingServer();
                server.OnMessageReceivedHandler = OnMessageReceived;
                server.Start();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method is responsible for main execution of console application.
        /// </summary>
        /// <param name="args">The string args received by parameters.</param>
        static void Main(string[] args)
        {
            try
            {
                _networkListenerType = NetworkListenerType.UDP;

                var server = new KingServer();
                server.OnMessageReceivedHandler = OnMessageReceived;
                server.OnClientConnectedHandler = OnClientConnectedHandler;
                server.Start(_networkListenerType);

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method is responsible for run the server.
        /// </summary>
        public void Run()
        {
            try
            {
                _networkPlayersDictionary = new Dictionary <IClient, NetworkPlayer>();

                _server = new KingServer();

                _server.OnMessageReceivedHandler    = OnMessageReceived;
                _server.OnClientConnectedHandler    = OnClientConnectedHandler;
                _server.OnClientDisconnectedHandler = OnClientDisconnectedHandler;
                _server.OnServerStartedHandler      = OnServerStartedHandler;

                _server.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }