本文整理汇总了C#中WebSocketContext类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketContext类的具体用法?C# WebSocketContext怎么用?C# WebSocketContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketContext类属于命名空间,在下文中一共展示了WebSocketContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public override WebSocketPackageInfo Handle(IAppSession session, WebSocketContext context, IList<ArraySegment<byte>> data)
{
var total = data.Sum(d => d.Count);
var payloadLength = context.PayloadLength;
var text = Encoding.UTF8.GetString(data, total - payloadLength, payloadLength);
return new WebSocketPackageInfo(text, ServiceProvider.StringParser);
}
示例2: WebSocket
// As server
internal WebSocket(HttpListenerWebSocketContext context, string protocol)
{
_context = context;
_protocol = protocol;
_closeContext = context.Close;
_secure = context.IsSecureConnection;
_stream = context.Stream;
init();
}
示例3: WebSocket
internal WebSocket(TcpListenerWebSocketContext context)
: this()
{
_uri = context.Path.ToUri();
_context = context;
_tcpClient = context.Client;
_wsStream = context.Stream;
_endPoint = context.ServerEndPoint;
_isClient = false;
_isSecure = context.IsSecureConnection;
}
示例4: customCheckHandshakeRequest
// As server
private bool customCheckHandshakeRequest (WebSocketContext context, out string message)
{
message = null;
return _handshakeRequestChecker == null
|| (message = _handshakeRequestChecker (context)) == null;
}
示例5: checkIfValidHandshakeRequest
// As server
private string checkIfValidHandshakeRequest (WebSocketContext context)
{
var headers = context.Headers;
return context.RequestUri == null
? "Specifies an invalid Request-URI."
: !context.IsWebSocketRequest
? "Not a WebSocket connection request."
: !validateSecWebSocketKeyHeader (headers["Sec-WebSocket-Key"])
? "Includes an invalid Sec-WebSocket-Key header."
: !validateSecWebSocketVersionClientHeader (headers["Sec-WebSocket-Version"])
? "Includes an invalid Sec-WebSocket-Version header."
: CustomHandshakeRequestChecker (context);
}
示例6: init
// As server
private void init(WebSocketContext context)
{
_context = context;
_uri = context.Path.ToUri ();
_secure = context.IsSecureConnection;
_client = false;
}
示例7: checkIfValidHandshakeRequest
// As server
private string checkIfValidHandshakeRequest(WebSocketContext context)
{
var headers = context.Headers;
return !context.IsWebSocketRequest
? "Not WebSocket connection request."
: !validateHostHeader (headers ["Host"])
? "Invalid Host header."
: !validateSecWebSocketKeyHeader (headers ["Sec-WebSocket-Key"])
? "Invalid Sec-WebSocket-Key header."
: !validateSecWebSocketVersionClientHeader (headers ["Sec-WebSocket-Version"])
? "Invalid Sec-WebSocket-Version header."
: CustomHandshakeRequestChecker (context);
}
示例8: Start
internal void Start(WebSocketContext context, WebSocketSessionManager sessions)
{
if (_websocket != null) {
_websocket.Log.Error ("This session has already been started.");
context.WebSocket.Close (HttpStatusCode.ServiceUnavailable);
return;
}
_context = context;
_sessions = sessions;
_websocket = context.WebSocket;
_websocket.CustomHandshakeRequestChecker = checkIfValidConnectionRequest;
_websocket.EmitOnPing = _emitOnPing;
_websocket.IgnoreExtensions = _ignoreExtensions;
_websocket.Protocol = _protocol;
var waitTime = sessions.WaitTime;
if (waitTime != _websocket.WaitTime)
_websocket.WaitTime = waitTime;
_websocket.OnOpen += onOpen;
_websocket.OnMessage += onMessage;
_websocket.OnError += onError;
_websocket.OnClose += onClose;
_websocket.ConnectAsServer ();
}
示例9: Handle
public override WebSocketPackageInfo Handle(IAppSession session, WebSocketContext context, IList<ArraySegment<byte>> data)
{
return new WebSocketPackageInfo(data, ServiceProvider.BinaryDataParser, ServiceProvider.StringParser);
}
示例10: Parse
public static RequestHandshake Parse(WebSocketContext context)
{
return new RequestHandshake {
Headers = context.Headers,
HttpMethod = "GET",
RequestUri = context.RequestUri,
ProtocolVersion = HttpVersion.Version11
};
}
示例11: StartSession
internal void StartSession(WebSocketContext context)
{
var session = CreateSession ();
session.Start (context, Sessions);
}
示例12: checkIfValidHandshakeRequest
// As server
private string checkIfValidHandshakeRequest(WebSocketContext context)
{
var headers = context.Headers;
return !context.IsWebSocketRequest
? "Not WebSocket connection request."
: !validateHostHeader (headers ["Host"])
? "Invalid Host header."
: !validateSecWebSocketKeyHeader (headers ["Sec-WebSocket-Key"])
? "Invalid Sec-WebSocket-Key header."
: !validateSecWebSocketVersionClientHeader (headers ["Sec-WebSocket-Version"])
? "Invalid Sec-WebSocket-Version header."
: !validateCookies (context.CookieCollection, _cookies)
? "Invalid Cookies."
: null;
}
示例13: Handle
public abstract WebSocketPackageInfo Handle(IAppSession session, WebSocketContext context, IList<ArraySegment<byte>> data);
示例14: checkHandshakeRequest
private string checkHandshakeRequest(WebSocketContext context)
{
return _originValidator != null && !_originValidator (context.Origin)
? "Includes no Origin header, or it has an invalid value."
: _cookiesValidator != null
&& !_cookiesValidator (context.CookieCollection, context.WebSocket.CookieCollection)
? "Includes no cookie, or an invalid cookie exists."
: null;
}
示例15: StartSession
/// <summary>
/// Starts a new session to the WebSocket service using the specified <see cref="WebSocketContext"/>.
/// </summary>
/// <param name="context">
/// A <see cref="WebSocketContext"/> that contains a WebSocket connection request objects.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="context"/> is <see langword="null"/>.
/// </exception>
internal void StartSession(WebSocketContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
var session = CreateSession ();
session.Start (context, Sessions);
}