From 045c3ebf9b7c2cab7d522f5094f27d57733c2c09 Mon Sep 17 00:00:00 2001 From: Donald Pillou Date: Thu, 2 Jan 2014 15:52:09 +0100 Subject: [PATCH] Answer a ping with a pong Websocket clients are supposed to do so. --- easywsclient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/easywsclient.cpp b/easywsclient.cpp index 1957db4..8a8f1e9 100644 --- a/easywsclient.cpp +++ b/easywsclient.cpp @@ -297,7 +297,11 @@ class _RealWebSocket : public easywsclient::WebSocket std::string data(rxbuf.begin()+ws.header_size, rxbuf.begin()+ws.header_size+(size_t)ws.N); callable((const std::string) data); } - else if (ws.opcode == wsheader_type::PING) { } + else if (ws.opcode == wsheader_type::PING) { + if (ws.mask) { for (size_t i = 0; i != ws.N; ++i) { rxbuf[i+ws.header_size] ^= ws.masking_key[i&0x3]; } } + std::string data(rxbuf.begin()+ws.header_size, rxbuf.begin()+ws.header_size+(size_t)ws.N); + sendData(wsheader_type::PONG, data); + } else if (ws.opcode == wsheader_type::PONG) { } else if (ws.opcode == wsheader_type::CLOSE) { close(); } else { fprintf(stderr, "ERROR: Got unexpected WebSocket message.\n"); close(); }