1

I just started using the libnghttp2_asio library and ran the example client and server mentioned at this link. However, I am unable to connect to the server after an initial failure despite sending subsequent requests, i.e, I would like to know how to make subsequent requests for a time duration if there was no response from the server or if the server was down in the first attempt.

So, I tried adding this piece of code in the sess.on_error callback in the client code

sess.on_error([](const boost::system::error_code &ec){
    std::cerr << " error : " << ec.message() << std::endl;
    boost::asio::io_service io_service;
    int num_retries = 100;
    for(int  i = 0; i < num_retries; i++){
        this_thread::sleep_for(std::chrono::milliseconds(1000));
        cout << "retry attempt "<< i+1 << endl;
        session sess(io_service, "localhost", "3000");
   }
});

Despite doing this, I find that the sess.on_connect is not being invoked after an initial failure, i.e. to test this, I first run the client without starting the server, but then, later even after starting the server, the connection isn't established.

error: Connection refused
retry attempt 1
retry attempt 2
retry attempt 3
retry attempt 4
retry attempt 5
retry attempt 6
...
retry attempt 100

Any help would be appreciated. Thanks!

Jitesh Malipeddi
  • 2,150
  • 3
  • 17
  • 37

0 Answers0