I use http_listener of cpprest(casablanca) library as my server.
after some request from client I want to change uri that this listener listen to it in handle_post of listener.
In main.cpp I have this code:
changeIpOrPort = 0;
try
{
while (true){
web::http::experimental::listener::http_listener *MyListener = new web::http::experimental::listener::http_listener(uri("http://"+MyserverIpaddress+":"+MyserverPort+"/"));
MyListener->support(methods::GET, handle_get);
MyListener->support(methods::POST, handle_post);
MyListener
->open()
.then([&MyListener]() {TRACE(L"\n Again starting to listen\n"); })
.wait();
std::cout <<"current ip server is :"<<MyserverIpaddress<<" current port is "<< MyserverPort <<endl;
changeIpOrPort = 0;
while(changeIpOrPort == 0);
MyListener->close();
delete(MyListener);
}
}
catch (exception const & e)
{
wcout <<L"exception is " <<e.what() << endl;
}
in handle_post function that define in source.cpp , when I recognize that client want change server Ip address , I set changeIpOrPort to 1.
but i raise an exception :
bind: Cannot assign requested address
does anybody know why this exception raise and how to fix it?