microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.89k stars 1.63k forks source link

EOF error #1775

Open DerXanRam opened 8 months ago

DerXanRam commented 8 months ago

Hello guys. I'm using restcpp for subscribing and listening "pending transactions". But some times throws EOF error and my program brokes at runtime. My code sinnipet i use to subscribe web socket is

void socks()
{
    websocket_client client;
    client.connect("wss://bsc-mainnet.blastapi.io/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").wait();
    string a = R"({"jsonrpc":"2.0","method":"eth_subscribe","params":["newPendingTransactions"],"id":1})";
    websocket_outgoing_message out_msg, unsub_w;

    out_msg.set_utf8_message(a);
    client.send(out_msg).wait();

    while (true)
    {
        client.receive().then([](websocket_incoming_message in_msg)
                              { return in_msg.extract_string(); })
            .then(
                [](string body)
                {
                    ret_str = body;
                    cout << j << " " << ret_str;
                })
            .wait();
        j++;
    }
    client.close().wait();
}

my question is how to avoid this error or how to catch it and handle it to prevent my program from sudden failure? please help :pray: