Skip to content

Commit d32b233

Browse files
committed
Merge pull request dhbaird#27 from donpillou/sendPing
Answer a ping with a pong
2 parents c90f15d + 045c3eb commit d32b233

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

easywsclient.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ class _RealWebSocket : public easywsclient::WebSocket
297297
std::string data(rxbuf.begin()+ws.header_size, rxbuf.begin()+ws.header_size+(size_t)ws.N);
298298
callable((const std::string) data);
299299
}
300-
else if (ws.opcode == wsheader_type::PING) { }
300+
else if (ws.opcode == wsheader_type::PING) {
301+
if (ws.mask) { for (size_t i = 0; i != ws.N; ++i) { rxbuf[i+ws.header_size] ^= ws.masking_key[i&0x3]; } }
302+
std::string data(rxbuf.begin()+ws.header_size, rxbuf.begin()+ws.header_size+(size_t)ws.N);
303+
sendData(wsheader_type::PONG, data);
304+
}
301305
else if (ws.opcode == wsheader_type::PONG) { }
302306
else if (ws.opcode == wsheader_type::CLOSE) { close(); }
303307
else { fprintf(stderr, "ERROR: Got unexpected WebSocket message.\n"); close(); }

0 commit comments

Comments
 (0)