-
Notifications
You must be signed in to change notification settings - Fork 279
Binary data in Message? #30
Comments
See SocketServerBase::Message::fin_rsv_opcode. For instance inside the onmessage lamda: |
Thanks. Do you mean we can use fin_rsv_opcode to test if the message contains binary data? I guess my problem is that I know for sure the message will contain binary data, but I want to get the data. I check the source (https://github.com/eidheim/Simple-WebSocket-Server/blob/master/server_ws.hpp#L117) and found the class Message doesn't seem to provide a way to access the data (string() will just return the data parsed as string, right?). I guess maybe I need to modify class Message a bit to access the data? I am new to C++, so my question may sound stupid :) |
Yes, fin_rsv_opcode is a way to check if the data is binary or not. https://github.com/eidheim/Simple-WebSocket-Server/blob/master/server_ws.hpp#L117 subclasses std::istream, so you can use std::istream::read (Message::read). You can also use the Message::string() method as it does not matter if its return is binary or text, the only difference is how you would use it. For instance, you would not try to output binary data to a terminal. |
I see. Thank you so much for the help. I will test it after work. |
Is it possible to get the binary data from WsServer::Message? The idea is that we don't necessary always send strings, in my project, I am actually sending binaries.
Thanks.
The text was updated successfully, but these errors were encountered: