Stream truncated (Boost.Beast / Boost.Asio)

  boost, boost-asio, boost-beast, c++, websocket

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:

  1. 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 .

  2. 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 .

  3. 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.

  4. 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";
    

`

`

  1. In program code from step 1 replace ws.handshake(host, "/"); on ws.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".

Source: Windows Questions C++

One Reply to “Stream truncated (Boost.Beast / Boost.Asio)”

LEAVE A COMMENT