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


C# IRequest.GetWebSocketVersion方法代码示例

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


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

示例1: Negotiate

        public IHandler Negotiate(IRequest request, Func<byte[], Task> sendAction)
        {
            var version = request.GetWebSocketVersion();
            if (_protocolSelector.SupportedVersions.Contains(version))
                return _handshakeNegotiator.Negotiate(request, sendAction);

            throw new HandshakeException(HttpStatusCode.BadRequest);
        }
开发者ID:ReactiveMarkets,项目名称:Styx,代码行数:8,代码来源:WebSocketVersionFilteringHandshakeNegotiator.cs

示例2: Negotiate

        public IHandler Negotiate(IRequest request, Func<byte[], Task> sendAction)
        {
            var path = new PathBuilder(request.Path).Build();

            var route = _routeResolver.Resolve(path);
            if (route.Equals(Route.Empty))
                throw new HandshakeException(HttpStatusCode.NotFound);

            var webSocketHandler = route.Handler();

            var version = request.GetWebSocketVersion();

            var handler = _protocolSelector.Select(version, m => webSocketHandler.OnMessage(m), () => webSocketHandler.OnClose(), b => webSocketHandler.OnBinary(b), b => webSocketHandler.OnPing(b), b => webSocketHandler.OnPong(b), ex => webSocketHandler.OnError(ex));

            var routeParameters = _routeParametersBuilder.Build(route.Path, path);

            var queryParameters = _queryParametersBuilder.Build(path);

            var subProtocol = _subProtocolNegotiator.Negotiate(_hostConfiguration.SupportedSubProtocols, request.GetWebSocketProtocols());

            webSocketHandler.Query = queryParameters;
            webSocketHandler.Route = routeParameters;
            webSocketHandler.Context = request.ToContext(subProtocol);
            webSocketHandler.SendAction = (message, frameType) =>
            {
                switch (frameType)
                {
                    case FrameType.Binary:
                        sendAction(handler.FrameBinary(message));
                        break;
                    case FrameType.Ping:
                        sendAction(handler.FramePing(message));
                        break;
                    case FrameType.Pong:
                        sendAction(handler.FramePong(message));
                        break;
                    case FrameType.Text:
                        sendAction(handler.FrameText(message));
                        break;
                    case FrameType.Close:
                        sendAction(handler.FrameClose(WebSocketStatusCode.NormalClosure));
                        break;
                }
            };

            var requestKey = request.Headers["Sec-WebSocket-Key"];

            var response = new WebSocketAcceptResponse(requestKey, subProtocol);
            sendAction(response.ToBytes()).ContinueWith(t => webSocketHandler.OnOpen());

            return handler;
        }
开发者ID:ReactiveMarkets,项目名称:Styx,代码行数:52,代码来源:DefaultHandshakeNegotiator.cs


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