Example #1
0
        public void Interview(Socket socket)
        {
            try
            {
                using (var client = new NetClient(socket))
                {
                    if (_gateway.ServerCert != null)
                    {
                        var sslts = new SslStream(client.InnerStream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
                        sslts.AuthenticateAsServer(_gateway.ServerCert, true, NetClient.SSLProtocols, false);
                        client.InnerStream = sslts;
                    }

                    while (true)
                    {
                        var cmd = GetRequestCommand(client);
                        if (cmd == null)
                        {
                            client.Write(Encoding.UTF8.GetBytes("ok"));
                            return;
                        }
                        _logger?.LogDebug("type:{0} content:{1}", cmd.Type, cmd.Content);

                        _manager.AllocHandler(cmd)?.Handle(client, cmd);

                        if (client.HasSocketException || !client.KeepAlive)
                        {
                            break;
                        }
                    }
                }
            }
            catch (SocketException)
            {
            }
            catch (System.IO.IOException ex)
            {
                if (ex.HResult != -2146232800)
                {
                    _logger?.LogError(ex, ex.Message);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, ex.Message);
            }
        }
Example #2
0
        public void Interview(Socket socket)
        {
            try
            {
                using (var client = new NetClient(socket))
                {
                    var cmd = client.ReadServiceObject <GatewayCommand>();
                    _logger?.LogDebug("收到命令,type:{0} content:{1}", cmd.Type, cmd.Content);

                    _manager.AllocHandler(cmd)?.Handle(client, cmd);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, ex.Message);
            }
        }
Example #3
0
        public void Interview(Socket socket)
        {
            try
            {
                using (var client = new NetClient(socket))
                {
                    var cmd = client.ReadServiceObject <GatewayCommand>();
                    if (cmd == null)
                    {
                        client.Write(Encoding.UTF8.GetBytes("ok"));
                        return;
                    }
                    _logger?.LogDebug("收到命令,type:{0} content:{1}", cmd.Type, cmd.Content);

                    _manager.AllocHandler(cmd)?.Handle(client, cmd);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, ex.Message);
            }
        }