Answer a ping with a pong

Websocket clients are supposed to do so.
This commit is contained in:
Donald Pillou
2014-01-02 15:52:09 +01:00
parent c90f15d87f
commit 045c3ebf9b
+5 -1
View File
@@ -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(); }