CCan't create http_listener object.

Oct 17, 2014 at 7:39 PM
Edited Oct 17, 2014 at 8:03 PM
Hi all. I tried to create http_listener but all stop in .open function, why? (Windows 7, VS 2013)
Please help.
#include <cpprest\http_listener.h>
#include <cpprest\http_client.h>
#include <iostream>
 
using namespace std;
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;
using namespace web::http::experimental::listener;
 
void get_handle(http_request resp)
{
 
}
 
int main(int argc, char** argv)
{
    http_listener listener(U("http://127.0.0.1:8181"));
 
    listener.support(methods::GET, get_handle);
 
    listener.open().then([&listener]()
    {
        cout << "Server start" << endl;
        listener.close();
    }).wait();
 
    cout << "Listener stop" << endl;
 
    system("pause");
    return 0;
}
Coordinator
Oct 22, 2014 at 11:36 PM
Hi rbkblhjy,

Looking at your code it appears you are starting the listener by calling http_listener::open() and then once it has been successfully opened you are immediately stopping the listener by calling http_listener::close(). After you call close no new requests will be accepted. Why don't you actually reply to the http_request in your get_handle function and call close at some later time?

Steve