From f9e6b51a722e5d8e9207f4c7f5e01a98080cf9ea Mon Sep 17 00:00:00 2001 From: theAirC Date: Thu, 8 Dec 2016 22:04:15 +0200 Subject: [PATCH] Detection of closed websocket connection When the websocket connection is closed, a non-empty frame (n>0) may be received with FRAME_OP_CLOSE flag bit set. Tested with chrome 54.0.2840.99 ; after establishing the websocket connection, if the connection is not closed by javascript and the tab is closed, a frame of length n=2 is received with FRAME_OP_CLOSE flag set. --- Net/samples/WebSocketServer/src/WebSocketServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Net/samples/WebSocketServer/src/WebSocketServer.cpp b/Net/samples/WebSocketServer/src/WebSocketServer.cpp index 440ab7d5d..8e067129e 100644 --- a/Net/samples/WebSocketServer/src/WebSocketServer.cpp +++ b/Net/samples/WebSocketServer/src/WebSocketServer.cpp @@ -119,7 +119,7 @@ public: app.logger().information(Poco::format("Frame received (length=%d, flags=0x%x).", n, unsigned(flags))); ws.sendFrame(buffer, n, flags); } - while (n > 0 || (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE); + while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE); app.logger().information("WebSocket connection closed."); } catch (WebSocketException& exc)