Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Binary data in Message? #30

Closed
qingxiang-jia opened this issue Apr 24, 2016 · 4 comments
Closed

Binary data in Message? #30

qingxiang-jia opened this issue Apr 24, 2016 · 4 comments

Comments

@qingxiang-jia
Copy link

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.

@eidheim
Copy link
Owner

eidheim commented Apr 25, 2016

See SocketServerBase::Message::fin_rsv_opcode. For instance inside the onmessage lamda: message->fin_rsv_opcode. If I remember correctly, the codes are the same as when sending to the client: https://github.com/eidheim/Simple-WebSocket-Server/blob/master/server_ws.hpp#L224

@qingxiang-jia
Copy link
Author

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 :)

@eidheim
Copy link
Owner

eidheim commented Apr 25, 2016

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.

@qingxiang-jia
Copy link
Author

I see. Thank you so much for the help. I will test it after work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants