C++ 使用CPPRestSDK进行客户端进程轮询

C++ 使用CPPRestSDK进行客户端进程轮询,c++,rest,asynchronous,casablanca,C++,Rest,Asynchronous,Casablanca,我有一个需要一段时间才能执行的任务,我想启动它并通过Rest请求广播它的进度。我已经用CPPRestSDK设置了一个带有客户端进程轮询的侦听器,但是我想不出一种方法来实现这一点 我已经看到了,但是我只能看到一种使用它的方法,如果我设置一个websocket来将进度推送到客户端。但我更愿意使用轮询来监控客户端的进度。这是一个解决方案,但我不知道如何用这个lib实现它。首先,您需要用一个指向进度侦听器的URL进行响应 int progress = 0; std::string progURL = "

我有一个需要一段时间才能执行的任务,我想启动它并通过Rest请求广播它的进度。我已经用CPPRestSDK设置了一个带有客户端进程轮询的侦听器,但是我想不出一种方法来实现这一点


我已经看到了,但是我只能看到一种使用它的方法,如果我设置一个websocket来将进度推送到客户端。但我更愿意使用轮询来监控客户端的进度。这是一个解决方案,但我不知道如何用这个lib实现它。

首先,您需要用一个指向进度侦听器的URL进行响应

int progress = 0;
std::string progURL = "http://www.example.com/listener"; 
std::thread progList = std::thread{&ProgressListener, progURL, std::ref(progress)};
web::http::http_response response(web::http::status_codes::Accepted);
response.headers().add("Location", requURL);
request.reply(response);
然后启动一个线程,允许您托管一个单独的侦听器

void ProgressListener( std::string progURL, double &progress ){
  web::http::experimental::listener::http_listener progListener(hostURL);
  progListener.support(web::http::methods::GET, [&](web::http::http_request request){
    web::http::http_response response;
    response.set_status_code(web::http::status_codes::OK);
    response.headers().add("Progress", progress); // You can call the header anything pretty much
    request.reply(response);
  }
}

然后,您需要与客户端轮询该url,并提取标题数据。

首先,您需要向进度侦听器发送url响应

int progress = 0;
std::string progURL = "http://www.example.com/listener"; 
std::thread progList = std::thread{&ProgressListener, progURL, std::ref(progress)};
web::http::http_response response(web::http::status_codes::Accepted);
response.headers().add("Location", requURL);
request.reply(response);
然后启动一个线程,允许您托管一个单独的侦听器

void ProgressListener( std::string progURL, double &progress ){
  web::http::experimental::listener::http_listener progListener(hostURL);
  progListener.support(web::http::methods::GET, [&](web::http::http_request request){
    web::http::http_response response;
    response.set_status_code(web::http::status_codes::OK);
    response.headers().add("Progress", progress); // You can call the header anything pretty much
    request.reply(response);
  }
}
然后,您需要与您的客户机轮询该url,并提取标题数据