How to open http_listener (error -> Address '' is already in use)

Sep 11, 2014 at 12:10 PM

i always getting error that address is in use when using this code
void ListenerOpen()
    try {
        web::http::experimental::listener::http_listener listener(L"");[&](web::http::http_request request){ request.reply(web::http::status_codes::OK, U("Hello, World!"));  }));;
    catch (std::exception &e) {
        std::cout << "caught error: " << e.what() << std::endl; cin.get();
error appear when i try to open listener.

Do you have some advice, or some good link to know why is this happen?
Sep 11, 2014 at 5:33 PM
Hi silent_,

Are you running the code in windows or Linux? What version of CppRest SDK are you using?

Sep 11, 2014 at 8:30 PM
hi zhelu,

version is C++ REST SDK 1.4.0, i run on windows 7 64x, visual studio 2013
Sep 11, 2014 at 8:32 PM
Hi silent_,

Without actually running anything my guess is that either some other service is actually already listening on port 80 or you aren't running your program with administrative privileges on Windows. On Windows to listen on port 80 this is a requirement.

Sep 11, 2014 at 8:44 PM
hi stevegates,

none of service running on port 80, and i have all privileges. I just download your examples from here, latest version "" and compile project bingrequest -> which work, and in same project put above code and try to run but always getting error that address is in use (when i put instead of http://localhost:8080/hello it's working).
Sep 11, 2014 at 10:24 PM
Hi silent_,

I think you're getting confused between the functionality of the listener and the client.

If you want to fetch a webpage, like in the BingRequest sample, you need to use the client. With the client, you can use any URL (such as and others).

However, if you want others to fetch webpages from you, you need to use the listener. With the listener, you can only use URLs that point to you. This usually means you need to use "localhost" instead of "". This is because "" doesn't point to you, it points to a site run by IANA.

Sep 11, 2014 at 11:11 PM
hi roschuma,

you have definitely right, i'm new in rsdk so many thing seems confused to me. I just realize that i need something like interceptor. My goal is to display in browser that site status is Forbidden when i get to the (like in this example ->butt i can get it work.

This is what i already try to intercept google and display in browser that site is Forbidden
void IntercetGoogle()
auto testAuthStage =
    [](http_request request, std::shared_ptr<http_pipeline_stage> next_stage) -> pplx::task < http_response >
    http_response response;
    wcout << response.extract_string().get() << endl;
    return pplx::task_from_result(response);

http_client client(L"");
``` This code don't work it want display in browser that site is Forbidden, why?