eidheim / Simple-WebSocket-Server

A very simple, fast, multithreaded, platform independent WebSocket (WS) and WebSocket Secure (WSS) server and client library implemented using C++11, Boost.Asio and OpenSSL. Created to be an easy way to make WebSocket endpoints in C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sending binary data fails

opened this issue · comments

Hi there,
first of all thank you for the easy to use framework!

I'am having issues when sending binary data to my webbrowser session.

The client is sending pure binary data (see this gist: https://gist.github.com/mojovski/ae912065ffd6e572a67ff0a29228c3a2)

The server is the provided ws_example.cpp from your repository: https://github.com/eidheim/Simple-WebSocket-Server/blob/master/ws_examples.cpp

The second client implemented in the webbrowser is simply listening on the endpoint and outputs the received data to console:
https://gist.github.com/mojovski/b6e1b0db0579d06bc015982043718358

The error I receive is:

test_websocket.html:20 WebSocket connection to 'ws://localhost:8080/echo_all' failed: Could not decode a text frame as UTF-8.

I assume, that somewhere in the WebSocket protocol implementation, the payload is set as "text".
From the specs https://tools.ietf.org/html/rfc6455#section-5.2
I may be that the opcode is not set properly from the simple-websocket-server.

Looking at the chrome-network data (the frame), the message says that the OpCode is -1
screenshot from 2017-04-24 16 33 22

I also tried to set the fin_rsv_opcode when using the method send but this didnt help:

client.send(send_stream, nullptr, 130 /*130 means binary*/);

Sending simple strings works by the way.

Thank you very much in advance for your support!

Some Updates

When I debug the data sent via wireshark, there is a second package, which is sent as "text" but also contains binary data.

It looks like this:
screenshot from 2017-04-24 17 08 15

If you like, you can have a look on the wireshark log here: https://drive.google.com/file/d/0B2fi7-kZoDhPNVI0aWxTNTVDT2c/view?usp=sharing

Hope this helps.

Ok, solved. The issue was that the example code did not consider to "echo" binary data.
I changed
https://github.com/eidheim/Simple-WebSocket-Server/blob/master/ws_examples.cpp#L102
to

server.send(a_connection, send_stream, nullptr, message->fin_rsv_opcode);

and it works.