/// <summary> /// On received action handler. /// </summary> /// <param name="context">The current client context.</param> private void OnReceivedActionHandler(Nequeo.Net.Provider.Context context) { try { // Store data until all headers have been read. if (Nequeo.Net.Utility.IsParse2CRLF(context.Request.Input, context.RequestBufferStore, _maxHeaderBufferStore)) { // Create the web socket context and set the headers. Nequeo.Net.WebSockets.WebSocketContext webSocketContext = CreateWebSocketContext(context); // Get the headers from the stream and assign the request data. bool headersExist = Nequeo.Net.WebSockets.Utility.SetRequestHeaders(webSocketContext, base.HeaderTimeout, base.MaximumReadLength, context.RequestBufferStore); // Create the response headers. CreateResponseHeaders(webSocketContext); // Make sure all handshaking has complete before continuing. if (!webSocketContext.HandshakeComplete) { // Not valid. throw new Exception("Not a valid WebSocket request."); } else { // Indicate that all web sockets after handshaking // is complete will run in async mode. webSocketContext.IsAsyncMode = true; // Create the central web socket context. CentralWebSocketContext centralWebSocketContext = new CentralWebSocketContext(webSocketContext); centralWebSocketContext.ConnectionID = webSocketContext.ConnectionID; centralWebSocketContext.Cookies = webSocketContext.WebSocketRequest.Cookies; centralWebSocketContext.Headers = webSocketContext.WebSocketRequest.Headers; centralWebSocketContext.IsAuthenticated = webSocketContext.IsAuthenticated; centralWebSocketContext.IsSecureConnection = webSocketContext.IsSecureConnection; centralWebSocketContext.SecWebSocketKey = webSocketContext.WebSocketRequest.SecWebSocketKey; centralWebSocketContext.SecWebSocketProtocols = webSocketContext.WebSocketRequest.SecWebSocketProtocols; centralWebSocketContext.SecWebSocketVersion = webSocketContext.WebSocketRequest.SecWebSocketVersion; centralWebSocketContext.SessionID = webSocketContext.SessionID; centralWebSocketContext.SocketState = webSocketContext.SocketState; centralWebSocketContext.UniqueIdentifier = webSocketContext.UniqueIdentifier; centralWebSocketContext.Url = webSocketContext.WebSocketRequest.Url; centralWebSocketContext.User = webSocketContext.User; // If the event has been assigned. if (OnWebSocketContext != null) { OnWebSocketContext(this, centralWebSocketContext); } // Write the response to the client. Nequeo.Net.WebSockets.WebSocketResponse response = webSocketContext.WebSocketResponse; response.WriteWebSocketHeaders(); // Create and assign the web socket. Nequeo.Net.WebSockets.WebSocket webSocket = new Nequeo.Net.WebSockets.WebSocket(); centralWebSocketContext.WebSocket = webSocket; // Save the web context state objects. SaveWebContext(context, webSocketContext); } } // If the maximum request buffer store has been reached then close the connection. if (context.RequestBufferStore.Length > _maxHeaderBufferStore) { throw new Exception("Maximum request buffer store has been reached."); } } catch (Exception) { // Close the connection and release all resources used for communication. context.Close(); } }