cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

EOF error

Open DerXanRam opened this issue 2 years ago • 0 comments

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:

DerXanRam avatar Nov 01 '23 07:11 DerXanRam