Пример #1
0
        public void Process()
        {
            byte[] commandBuf;
            int    command = 0;

            try
            {
                while (true)
                {
                    commandBuf = GetMessage(4);

                    command = BitConverter.ToInt32(commandBuf, 0);
                    if (command == 0)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine(new StringBuilder("Команда = " + command + " принята на обработку").ToString());
                        HandleCommand(command);
                    }
                }
            }
            catch (SocketException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine(new StringBuilder("Клиент c id = " + Id + " отключился от сервера").ToString());
                _server.RemoveClient(Id);
                _clientSocket.Shutdown(SocketShutdown.Both);
                _clientSocket.Close();
            }
        }