internal void StartSession(WebSocketContext context) { CreateSession ().Start (context, Sessions); }
private string checkIfValidConnectionRequest(WebSocketContext context) { return _originValidator != null && !_originValidator (context.Origin) ? "Invalid Origin header." : _cookiesValidator != null && !_cookiesValidator (context.CookieCollection, context.WebSocket.CookieCollection) ? "Invalid Cookies." : null; }
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.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 (); }
// As server private void releaseServerResources() { if (_closeContext == null) return; _closeContext (); _closeContext = null; _stream = null; _context = null; }
// As server internal WebSocket(TcpListenerWebSocketContext context, string protocol) { _context = context; _protocol = protocol; _closeContext = context.Close; _logger = context.Log; _secure = context.IsSecureConnection; _stream = context.Stream; _waitTime = TimeSpan.FromSeconds (1); init (); }
// 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); }