dhbaird / easywsclient

A short and sweet WebSocket client for C++
MIT License
749 stars 204 forks source link

Distinguishing text/binary messages #45

Open jpek42 opened 8 years ago

jpek42 commented 8 years ago

Hi -

Thanks for the work on this library. It's certainly the easiest-to-consume C++ WS library I've come across.

One thing that I don't see is a way to determine whether an incoming message is binary or text. The _dispatchBinary method gets the opcode, but then just eats it without telling the callable. It seems like it would make sense to pass the type on as well.

Or maybe I'm missing something in the way things are supposed to work.

dhbaird commented 8 years ago

Hi @jpek42, sorry for taking awhile to get back to this issue. This is a limitation of the API: The information about text or binary can be inspected based on which callback was called. I.e., two callbacks need to be registered, one for text and one for binary.

jpek42 commented 8 years ago

Thanks for the response. I guess it wasn't clear what those 2 methods were (dispatch, dispatchBinary). Are they just establishing callbacks? So there's no need to call them within the loop?

dhbaird commented 8 years ago

Hi @jpek42, the original issue you raise is accurate: this is a limitation of the API, and also unexpected/confusing.

The easiest solution would be: make sure that your service ever only sends one or the other (text or binary), and never mixes them.

The more better solution would be to fix the API. I will see if I can do that this weekend, or pull requests are also welcome. Thanks for reporting this issue.