Problem:
I'm trying to write a C++ websocket with Boost.Beast. Websocket is needed for interacting with binary.com API (code samples in different languages - https://developers.binary.com/demos). But at line "ws.read(buffer);" I get an error "stream truncated".
How to reproduce:
Program code - Boost.Beast example of WebSocket SSL client, synchronous - https://github.com/boostorg/beast/blob/develop/example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp .
Root certificates.hpp - needed for program code, you can take it from here - https://github.com/boostorg/beast/blob/develop/example/common/root_certificates.hpp .
Don't forget to change the top line in program code, this line is
#include "example/common/root_certificates.hpp
. If you placed your root_certificates.hpp from step 2 to another place, make sure your code can #include it.In program code from step 1 place this code:
argc = 4;
argv[0] = "websocket-client-sync";
argv[1] = "ws.binaryws.com";
argv[2] = "443";
argv[3] = "{\"ticks\":\"R_100\"}";
auto target = "/websockets/v3?app_id=1089";
- In program code from step 1 replace
ws.handshake(host, "/");
onws.handshake(host, target);
What I'm trying to get as result:
You can see if you go with this link - https://www.websocket.org/echo.html , in "Location:" type wss://ws.binaryws.com/websockets/v3?app_id=1089
and in "Message:" type {"ticks":"R_100"}
. And then click "Connect" and "Send".
HTTP 1.1 is allowed to turn a "stream truncated" message when the latest chunk has been received. So it depends on the server, but your client code (Boost Asio) should just ignore this message.
For example:
More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding