internal bool CheckWebSocketUpgradeRequest(HttpsContext httpConn) { if (WebSocketServer == null) { return(false); } HttpRequest httpReq = httpConn.HttpReq; HttpResponse httpResp = httpConn.HttpResp; string upgradeKey = httpReq.GetHeaderKey("Upgrade"); if (upgradeKey != null && upgradeKey == "websocket") { //1. websocket request come here first //2. web server can design what web socket server will handle this request, based on httpCon url string sec_websocket_key = httpReq.GetHeaderKey("Sec-WebSocket-Key"); string sec_websocket_extensions = httpReq.GetHeaderKey("Sec-WebSocket-Extensions"); Internal2.AbstractAsyncNetworkStream baseStream = httpConn.BaseStream; #if DEBUG baseStream.BeginWebsocketMode = true; #endif //backup data before unbind socket string webSocketInitPath = httpReq.Path; //-------------------- httpConn.UnBindSocket(false); //unbind but not close client socket //-------------------- WebSocketServer.RegisterNewWebSocket(baseStream, webSocketInitPath, sec_websocket_key, sec_websocket_extensions); //the bind client to websocket server return(true); } return(false); }
internal bool CheckWebSocketUpgradeRequest(HttpContext httpConn) { if (webSocketServer == null) { return(false); } HttpRequest httpReq = httpConn.HttpReq; HttpResponse httpResp = httpConn.HttpResp; string upgradeKey = httpReq.GetHeaderKey("Upgrade"); if (upgradeKey != null && upgradeKey == "websocket") { //1. websocket request come here first //2. web server can design what web socket server will handle this request, based on httpCon url string sec_websocket_key = httpReq.GetHeaderKey("Sec-WebSocket-Key"); Socket clientSocket = httpConn.RemoteSocket; //backup data before unbind socket string webSocketInitUrl = httpReq.Url; //-------------------- httpConn.UnBindSocket(false); //unbind but not close client socket //-------------------- webSocketServer.RegisterNewWebSocket(clientSocket, webSocketInitUrl, sec_websocket_key); //the bind client to websocket server return(true); } return(false); }