I have developed a VC++ listener application using Casablanca SDK. This is the source code.
int _tmain(int argc, _TCHAR* argv[])
{
__uri_builder uri(L"http://localhost:2001/");__
http_listener listener(uri.to_uri());
std::cout << "Welcome to Casablanca" << std::endl;
CheckOSVersion();
listener.support(methods::GET, [](http_request req)
{
HKEY hKey;
LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Casablanca", 0, KEY_READ, &hKey);
bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);
std::wstring strValueOfBinDir;
GetStringRegKey(hKey, L"Encryption", strValueOfBinDir, L"1");
GIDSdkWriteXML();
http_response response (status_codes::OK);
response.headers().add(U("Access-Control-Allow-Origin"), U("*"));
response.set_body(strValueOfBinDir, U("text/html"));
req.set_request_uri(L"requestpath");
req.reply(response);
});
listener.support(methods::PUT,[](http_request req)
{
std::cout << "Serving PUT" << std::endl;
req.reply(status_codes::OK, U("<html><body><h1>It works!</h1>(Casablanca, that is a POST Request.)</body></html>"),
U("text/html"));
});
listener.support(methods::POST,[](http_request req)
{
std::cout << "Serving POST" << std::endl;
req.extract_string(true).then([req](utility::string_t body)
{
std::wcout << body << std::endl;
//req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
});
});
listener.open().wait();
fgetc(stdin);
listener.close().wait();
}
Everything is working fine. But when I change this line__uri_builder uri(L"http://localhost:2001/");__
Where I replace the localhost with the IP Address, so that the server can be externally accessed. it crashes. Can someone tell me the solution to this?