当前位置: 首页>>代码示例>>C#>>正文


C# ITcpChannel.Close方法代码示例

本文整理汇总了C#中ITcpChannel.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ITcpChannel.Close方法的具体用法?C# ITcpChannel.Close怎么用?C# ITcpChannel.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITcpChannel的用法示例。


在下文中一共展示了ITcpChannel.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteConnectModules

        private async Task ExecuteConnectModules(ITcpChannel channel, IClientContext context)
        {
            var result = ModuleResult.Continue;

            for (var i = 0; i < _modules.Length; i++)
            {
                var connectMod = _modules[i] as IConnectionEvents;
                if (connectMod == null)
                    continue;

                try
                {
                    result = await connectMod.OnClientConnected(context);
                }
                catch (Exception exception)
                {
                    context.Error = exception;
                    result = ModuleResult.SendResponse;
                }

                if (result != ModuleResult.Continue)
                    break;
            }

            switch (result)
            {
                case ModuleResult.Disconnect:
                    channel.Close();
                    break;
                case ModuleResult.SendResponse:
                    channel.Send(context.ResponseMessage);
                    break;
            }
        }
开发者ID:zeroyou,项目名称:Griffin.Framework,代码行数:34,代码来源:LiteServer.cs

示例2: OnDecoderFailure

 private void OnDecoderFailure(ITcpChannel channel, Exception error)
 {
     var pos = error.Message.IndexOfAny(new[] {'\r', '\n'});
     var descr = pos == -1 ? error.Message : error.Message.Substring(0, pos);
     var response = new HttpResponseBase(HttpStatusCode.BadRequest, descr, "HTTP/1.1");
     channel.Send(response);
     channel.Close();
 }
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:8,代码来源:HttpListener.cs

示例3: OnDecoderFailure

 private void OnDecoderFailure(ITcpChannel channel, Exception error)
 {
     var pos = error.Message.IndexOfAny(new[] {'\r', '\n'});
     var descr = pos == -1 ? error.Message : error.Message.Substring(0, pos);
     var response = new HttpResponse(HttpStatusCode.BadRequest, descr, "HTTP/1.1");
     var counter = (int)channel.Data.GetOrAdd(HttpMessage.PipelineIndexKey, x => 1);
     response.Headers[HttpMessage.PipelineIndexKey] = counter.ToString();
     channel.Send(response);
     channel.Close();
 }
开发者ID:VladimirTyrin,项目名称:Griffin.Framework,代码行数:10,代码来源:HttpListener.cs

示例4: ExecuteModules

        private async Task ExecuteModules(ITcpChannel channel, ClientContext context)
        {
            var result = ModuleResult.Continue;

            for (var i = 0; i < _modules.Length; i++)
            {
                try
                {
                    await _modules[i].BeginRequestAsync(context);
                }
                catch (Exception exception)
                {
                    context.Error = exception;
                    result = ModuleResult.SendResponse;
                }
            }


            if (result == ModuleResult.Continue)
            {
                for (var i = 0; i < _modules.Length; i++)
                {
                    try
                    {
                        result = await _modules[i].ProcessAsync(context);
                    }
                    catch (Exception exception)
                    {
                        context.Error = exception;
                        result = ModuleResult.SendResponse;
                    }

                    if (result != ModuleResult.Continue)
                        break;
                }
            }


            try
            {
                await EndRequestAsync(context);
            }
            catch (Exception exception)
            {
                if (context.ResponseMessage == null)
                    context.ResponseMessage = exception;
                result = ModuleResult.Disconnect;
            }

            if (context.ResponseMessage != null)
                channel.Send(context.ResponseMessage);

            if (result == ModuleResult.Disconnect)
            {
                channel.Close();
            }
        }
开发者ID:ricklxm,项目名称:Griffin.Framework,代码行数:57,代码来源:LiteServer.cs

示例5: OnMessage

        /// <summary>
        /// Handles the upgrade
        /// </summary>
        /// <param name="source">Channel that we've received a request from</param>
        /// <param name="msg">Message received.</param>
        protected override void OnMessage(ITcpChannel source, object msg)
        {
            var httpMessage = msg as IHttpMessage;
            if (WebSocketUtils.IsWebSocketUpgrade(httpMessage))
            {
                if (httpMessage is IHttpRequest) // server mode
                {
                    var args = new WebSocketClientConnectEventArgs(source, (IHttpRequest) httpMessage);
                    WebSocketClientConnect(this, args);

                    if (args.MayConnect)
                    {
                        var webSocketKey = httpMessage.Headers["Sec-WebSocket-Key"];

                        // TODO: why not provide the response in the WebSocketClientConnectEventArgs event?
                        var response = new WebSocketUpgradeResponse(webSocketKey);

                        source.Send(response);

                        WebSocketClientConnected(this,
                            new WebSocketClientConnectedEventArgs(source, (IHttpRequest) httpMessage, response));
                    }
                    else if (args.SendResponse)
                    {
                        var response = new HttpResponseBase(HttpStatusCode.NotImplemented, "Not Implemented", "HTTP/1.1");
                        if (args.Response != null)
                            response.Body = args.Response;

                        source.Send(response);
                    }
                    return;
                }

                if (httpMessage is IHttpResponse) // client mode
                {
                    WebSocketClientConnected(this,
                        new WebSocketClientConnectedEventArgs(source, null, (IHttpResponse) httpMessage));
                }
            }

            var webSocketMessage = msg as IWebSocketMessage;
            if (webSocketMessage != null)
            {
                // standard message responses handled by listener
                switch (webSocketMessage.Opcode)
                {
                    case WebSocketOpcode.Ping:
                        source.Send(new WebSocketMessage(WebSocketOpcode.Pong, webSocketMessage.Payload));
                        return;
                    case WebSocketOpcode.Close:
                        source.Send(new WebSocketMessage(WebSocketOpcode.Close));
                        source.Close();

                        WebSocketClientDisconnected(this,
                            new ClientDisconnectedEventArgs(source, new Exception("WebSocket closed")));
                        return;
                }

                _webSocketMessageReceived(source, webSocketMessage);
                return;
            }

            base.OnMessage(source, msg);
        }
开发者ID:jakubmacek,项目名称:Griffin.Framework,代码行数:69,代码来源:WebSocketListener.cs


注:本文中的ITcpChannel.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。