本文整理汇总了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);
}
示例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;
}