|
|
@@ -36,8 +36,9 @@ public:
|
|
|
~MyContext() {
|
|
|
}
|
|
|
|
|
|
- int handleMessage(const std::string& msg) {
|
|
|
- printf("onmessage: %s\n", msg.c_str());
|
|
|
+ int handleMessage(const std::string& msg, enum ws_opcode opcode) {
|
|
|
+ printf("onmessage(type=%s len=%d): %.*s\n", opcode == WS_OPCODE_TEXT ? "text" : "binary",
|
|
|
+ (int)msg.size(), (int)msg.size(), msg.data());
|
|
|
return msg.size();
|
|
|
}
|
|
|
|
|
|
@@ -72,7 +73,7 @@ int main(int argc, char** argv) {
|
|
|
};
|
|
|
ws.onmessage = [](const WebSocketChannelPtr& channel, const std::string& msg) {
|
|
|
MyContext* ctx = channel->getContext<MyContext>();
|
|
|
- ctx->handleMessage(msg);
|
|
|
+ ctx->handleMessage(msg, channel->opcode);
|
|
|
};
|
|
|
ws.onclose = [](const WebSocketChannelPtr& channel) {
|
|
|
printf("onclose\n");
|