コード例 #1
0
        public void Request(HttpConnection connection, string clientAddress, byte[] data)
        {
            string paramString = string.Empty;

            try
            {
                paramString = Encoding.ASCII.GetString(data);
                PacketMessage packet = ParsePacketMessage(clientAddress, paramString, ConnectType.Http);
                packet.Head.SSID = connection.SSID.ToString("N");
                HttpConnectionManager.Push(connection);

                if (ReceiveCompleted != null)
                {
                    //分发送到游戏服
                    byte[] packData   = packet.ToByte();
                    string successMsg = string.Format("{0}>>{1}接收到{2}字节!",
                                                      DateTime.Now.ToString("HH:mm:ss:ms"), clientAddress, data.Length);
                    ReceiveCompleted.BeginInvoke(clientAddress, packData, OnReceiveCompleted, successMsg);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Receive form http request:{0} error:{1}", paramString, ex);
            }
        }
コード例 #2
0
        private static ServiceContext CreateServiceContext(IOptions <KestrelServerOptions> options, ILoggerFactory loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            var serverOptions     = options.Value ?? new KestrelServerOptions();
            var logger            = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel");
            var trace             = new KestrelTrace(logger);
            var connectionManager = new HttpConnectionManager(
                trace,
                serverOptions.Limits.MaxConcurrentUpgradedConnections);

            var systemClock            = new SystemClock();
            var dateHeaderValueManager = new DateHeaderValueManager(systemClock);

            var httpHeartbeatManager = new HttpHeartbeatManager(connectionManager);
            var heartbeat            = new Heartbeat(
                new IHeartbeatHandler[] { dateHeaderValueManager, httpHeartbeatManager },
                systemClock,
                DebuggerWrapper.Singleton,
                trace);

            // TODO: This logic will eventually move into the IConnectionHandler<T> and off
            // the service context once we get to https://github.com/aspnet/KestrelHttpServer/issues/1662
            PipeScheduler scheduler = null;

            switch (serverOptions.ApplicationSchedulingMode)
            {
            case SchedulingMode.Default:
            case SchedulingMode.ThreadPool:
                scheduler = PipeScheduler.ThreadPool;
                break;

            case SchedulingMode.Inline:
                scheduler = PipeScheduler.Inline;
                break;

            default:
                throw new NotSupportedException(CoreStrings.FormatUnknownTransportMode(serverOptions.ApplicationSchedulingMode));
            }

            return(new ServiceContext
            {
                Log = trace,
                HttpParser = new HttpParser <Http1ParsingHandler>(trace.IsEnabled(LogLevel.Information)),
                Scheduler = scheduler,
                SystemClock = systemClock,
                DateHeaderValueManager = dateHeaderValueManager,
                ConnectionManager = connectionManager,
                Heartbeat = heartbeat,
                ServerOptions = serverOptions,
            });
        }
コード例 #3
0
        public Boolean LoginRequest(String UserName, String Password, IConnectionCallbacks callbackHandler, string requestID)
        {
            Console.WriteLine("LoginRequest start");

            lIConnectionCallbacks = callbackHandler;

            Boolean lIsNetworkAvailable = Utilities.CheckInternetConnection();

            if (lIsNetworkAvailable == false)
            {
                Console.WriteLine("LoginRequest lIsNetworkAvailable start");
                Dictionary <String, Object> lErrorDictionary = new Dictionary <String, Object>();
                lErrorDictionary[Defines.KeyConnectionErrorType]       = ConnectionErrorType.EConnectionError_NoNetwork;
                lErrorDictionary[Defines.KeyConnectionResponseMessage] = Defines.NetworkUnavailable;
                lIConnectionCallbacks.ConnectionFailedWithError(lErrorDictionary, requestID);

                return(lReturnValue);
            }

            if (callbackHandler == null)
            {
                Console.WriteLine("LoginRequest callbackHandler start");
                lReturnValue = false;
                return(lReturnValue);
            }

            if (String.IsNullOrEmpty(UserName))
            {
                Console.WriteLine("LoginRequest IsNullOrEmpty start");
                Dictionary <String, Object> lErrorDictionary = new Dictionary <String, Object>();
                lErrorDictionary[Defines.KeyConnectionErrorType]       = ConnectionErrorType.EConnectionError_LocalValidationFailed_NilOrBlankUserName;
                lErrorDictionary[Defines.KeyConnectionResponseMessage] = "Local Validation Failed Nil Or Blank UserName";
                lIConnectionCallbacks.ConnectionFailedWithError(lErrorDictionary, requestID);

                return(lReturnValue);
            }

            if (String.IsNullOrEmpty(Password))
            {
                Console.WriteLine("LoginRequest IsNullOrEmpty start");
                Dictionary <String, Object> lErrorDictionary = new Dictionary <String, Object>();
                lErrorDictionary[Defines.KeyConnectionErrorType]       = ConnectionErrorType.EConnectionError_LocalValidationFailed_NilOrBlankPassword;
                lErrorDictionary[Defines.KeyConnectionResponseMessage] = "EConnectionError_LocalValidationFailed_NilOrBlankPassword";
                lIConnectionCallbacks.ConnectionFailedWithError(lErrorDictionary, requestID);

                return(lReturnValue);
            }

            HttpConnectionManager lHttpConnectionManager = new HttpConnectionManager(this, requestID);
            String userNameAndPassword = UserName + "<@>" + Password;
            var    _ = lHttpConnectionManager.ExecuteWebRequestAsync(Utilities.getLoginURLAccordingToEnvironment(), userNameAndPassword);

            return(false);
        }
コード例 #4
0
ファイル: DlgEditPersonCore.cs プロジェクト: Baltasarq/Tacto
        private void OnConnectWeb()
        {
            try {
                var weber = new HttpConnectionManager(this.edWeb.Text);
                weber.Open();
            } catch (Exception exc)
            {
                Util.MsgError(this, AppInfo.Name, exc.Message);
            }

            return;
        }
コード例 #5
0
 private void OnResponseCompleted(HttpConnection connection, byte[] data)
 {
     HttpConnectionManager.Remove(connection);
     if (ResponseCompleted != null)
     {
         string address    = connection.Context.Request.UserHostAddress;
         string successMsg = string.Format("{0}>>准备发送到{1}[Http]的字节数:{2}byte...",
                                           DateTime.Now.ToString("HH:mm:ss:ms"), address, data.Length);
         Console.WriteLine(successMsg);
         ResponseCompleted(connection.Context.Response, data, 0, data.Length);
     }
 }
コード例 #6
0
 private void Initialize(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace)
 {
     LoggerFactory          = loggerFactory;
     Log                    = kestrelTrace;
     ThreadPool             = new LoggingThreadPool(Log);
     SystemClock            = new MockSystemClock();
     DateHeaderValueManager = new DateHeaderValueManager(SystemClock);
     ConnectionManager      = new HttpConnectionManager(Log, ResourceCounter.Unlimited);
     HttpParser             = new HttpParser <Http1ParsingHandler>(Log.IsEnabled(LogLevel.Information));
     ServerOptions          = new KestrelServerOptions
     {
         AddServerHeader = false
     };
 }
コード例 #7
0
ファイル: DlgEditPersonCore.cs プロジェクト: Baltasarq/Tacto
        private void OnConnectMap()
        {
            string url = HttpConnectionManager.UrlGMapsSearch
                         + this.edAddress.Text.Trim().Replace(' ', '+');

            try {
                var weber = new HttpConnectionManager(url);
                weber.Open();
            } catch (Exception exc)
            {
                Util.MsgError(this, AppInfo.Name, exc.Message);
            }

            return;
        }
コード例 #8
0
        public Boolean GetDealerData(String searchType, String param1, String param2, IConnectionCallbacks callbackHandler, string requestID)
        {
            lIConnectionCallbacks = callbackHandler;
            Boolean lIsNetworkAvailable = Utilities.CheckInternetConnection();

            if (lIsNetworkAvailable == false)
            {
                Dictionary <String, Object> lErrorDictionary = new Dictionary <String, Object>();
                lErrorDictionary[Defines.KeyConnectionErrorType]       = ConnectionErrorType.EConnectionError_NoNetwork;
                lErrorDictionary[Defines.KeyConnectionResponseMessage] = "Network Unavailable";
                callbackHandler.ConnectionFailedWithError(lErrorDictionary, requestID);

                return(lReturnValue);
            }

            if (callbackHandler == null)
            {
                lReturnValue = false;
                return(lReturnValue);
            }
            HttpConnectionManager lHttpConnectionManager = new HttpConnectionManager(this, requestID);
            string baseUrl = "";

            switch (searchType)
            {
            case "zip":
                baseUrl = Utilities.getDealersByZip() + "/" + param1 + "/" + param2 + "/";
                break;

            case "name":
                baseUrl = Utilities.getDealersByName() + "/" + param1 + "/";
                break;

            case "corp":
                baseUrl = Utilities.getDealersByRegion() + "/" + param1 + "/" + param2 + "/";
                break;

            default:
                break;
            }
            var _ = lHttpConnectionManager.ExecuteWebRequestAsync(baseUrl, "");

            return(true);
        }
コード例 #9
0
 protected override void OnSendToClient(PacketMessage packet)
 {
     if (packet.Head.ConnectType == ConnectType.Http)
     {
         string ssid       = packet.Head.SSID;
         var    connection = HttpConnectionManager.Get(ssid);
         if (connection != null)
         {
             connection.TimeoutTimer.Dispose();
             OnResponseCompleted(connection, packet.Content);
         }
         else
         {
             Console.WriteLine("Error of http connection is empty.");
         }
         return;
     }
     base.OnSendToClient(packet);
 }
        public void UnrootedConnectionsGetRemovedFromHeartbeat()
        {
            var connectionId          = "0";
            var trace                 = new Mock <IKestrelTrace>();
            var httpConnectionManager = new HttpConnectionManager(trace.Object, ResourceCounter.Unlimited);

            // Create HttpConnection in inner scope so it doesn't get rooted by the current frame.
            UnrootedConnectionsGetRemovedFromHeartbeatInnerScope(connectionId, httpConnectionManager, trace);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            var connectionCount = 0;

            httpConnectionManager.Walk(_ => connectionCount++);

            Assert.Equal(0, connectionCount);
            trace.Verify(t => t.ApplicationNeverCompleted(connectionId), Times.Once());
        }
        private void UnrootedConnectionsGetRemovedFromHeartbeatInnerScope(
            string connectionId,
            HttpConnectionManager httpConnectionManager,
            Mock <IKestrelTrace> trace)
        {
            var httpConnection = new HttpConnection(new HttpConnectionContext
            {
                ServiceContext = new TestServiceContext(),
                ConnectionId   = connectionId
            });

            httpConnectionManager.AddConnection(0, httpConnection);

            var connectionCount = 0;

            httpConnectionManager.Walk(_ => connectionCount++);

            Assert.Equal(1, connectionCount);
            trace.Verify(t => t.ApplicationNeverCompleted(connectionId), Times.Never());

            // Ensure httpConnection doesn't get GC'd before this point.
            GC.KeepAlive(httpConnection);
        }
コード例 #12
0
 public HttpConnectionDispatcher(HttpConnectionManager manager, ILoggerFactory loggerFactory)
 {
     _manager       = manager;
     _loggerFactory = loggerFactory;
     _logger        = _loggerFactory.CreateLogger <HttpConnectionDispatcher>();
 }
コード例 #13
0
ファイル: DlgEditPersonCore.cs プロジェクト: Baltasarq/Tacto
        private void OnConnectWeb()
        {
            try {
                var weber = new HttpConnectionManager( this.edWeb.Text );
                weber.Open();
            } catch(Exception exc)
            {
                Util.MsgError( this, AppInfo.Name, exc.Message );
            }

            return;
        }
コード例 #14
0
ファイル: DlgEditPersonCore.cs プロジェクト: Baltasarq/Tacto
        private void OnConnectMap()
        {
            string url = HttpConnectionManager.UrlGMapsSearch
                            + this.edAddress.Text.Trim().Replace( ' ', '+' );

            try {
                var weber = new HttpConnectionManager( url );
                weber.Open();
            } catch(Exception exc)
            {
                Util.MsgError( this, AppInfo.Name, exc.Message );
            }

            return;
        }
コード例 #15
0
        public static Listener CreateListener(bool ads, string listenerName, uint port, string routeName)
        {
            ConfigSource rdsSource;

            if (ads)
            {
                rdsSource = new ConfigSource
                {
                    Ads = new AggregatedConfigSource()
                };
            }
            else
            {
                rdsSource = new ConfigSource
                {
                    ApiConfigSource = new ApiConfigSource
                    {
                        ApiType = ApiType.Grpc,
                    }
                };

                rdsSource.ApiConfigSource.GrpcServices.Add(new GrpcService
                {
                    EnvoyGrpc = new EnvoyGrpc
                    {
                        ClusterName = XDS_CLUSTER
                    }
                });
            }

            var manager = new HttpConnectionManager
            {
                CodecType  = CodecType.Auto,
                StatPrefix = "http",
                Rds        = new Rds
                {
                    ConfigSource    = rdsSource,
                    RouteConfigName = routeName,
                }
            };

            manager.HttpFilters.Add(new HttpFilter
            {
                Name = Resources.FILTER_ENVOY_ROUTER,
            });

            var listener = new Listener
            {
                Name    = listenerName,
                Address = new Address
                {
                    SocketAddress = new SocketAddress
                    {
                        Address   = ANY_ADDRESS,
                        PortValue = port,
                        Protocol  = Protocol.Tcp,
                    }
                }
            };

            var filterChain = new FilterChain();

            filterChain.Filters.Add(new Filter
            {
                Name        = Resources.FILTER_HTTP_CONNECTION_MANAGER,
                TypedConfig = Any.Pack(manager),
            });

            listener.FilterChains.Add(filterChain);
            return(listener);
        }