rest sdk http_listener as a network server

Dec 28, 2013 at 8:04 PM
Edited Dec 28, 2013 at 8:05 PM
How to configure http_listener to listen on my ip address so other computers on the network can send requests to the server ?

http_listener listener(L"http://localhsot:9000"); // not working
http_listener listener(L"http://0.0.0.0:9000");
// run time error

http_listener listener(L"http://*:9000"); // run time error

I want to use http_listener as a server on my local network
.
Jan 3, 2014 at 9:45 PM
Hi I also encountered this problem.
You can solve this by using nginx as proxy on linux. This can also add https feature to your server.
Here is a small version of the needed nginx config file:
server {
        listen *:80;
        server_name localhost;

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:12345/;
                proxy_redirect http://localhost:12345/ https://$server_name/;
}
This script redirects all traffic to 12345. Now you just have to listen to
http_listener listener(L"http://localhost:12345");
Don't forget to the "support" calls.
Cheers,
Henry
Jan 4, 2014 at 4:50 PM
thank you very much :)
Feb 16, 2015 at 10:50 AM
HENRYTM wrote:
Hi I also encountered this problem.
You can solve this by using nginx as proxy on linux. This can also add https feature to your server.
Here is a small version of the needed nginx config file:
server {
        listen *:80;
        server_name localhost;

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:12345/;
                proxy_redirect http://localhost:12345/ https://$server_name/;
}
This script redirects all traffic to 12345. Now you just have to listen to
http_listener listener(L"http://localhost:12345");
Don't forget to the "support" calls.
Cheers,
Henry
@Henry I am using Casablanca SDK in Windows. Can you tell me how can I configure this nginx in windows so that I can use http_listener as a network server in Windows environment?
Feb 16, 2015 at 11:24 AM
@maverick786us has a windows version http://nginx.org/en/download.html.
Read the documentation, its the same as linux.
Feb 19, 2015 at 10:20 AM
@Golabi, if I am not wrong, the sole purpose of this SDK is to use http_listener in network so that one can connect with this listener in network. Now I have a situation, where I have the listener application in multiple PCs, and this listener application has to communicate with a WCF web service. Now in order to make it interact with the web service, the we service has to access this http_listener remotely.

Now there is a small problem. This http listener will be used in customer / client's PC. So configuring NGINX to each and every customer's PC will be a huge problem. Therefore can you also suggest me some alternative?

Thanks.
Feb 19, 2015 at 11:26 AM
@maverick786us
1- the purpose of this SDK is to provide a modern API to consume RESTFUL services. (http_listener is an experimental feature).

2- i had the same problem , i tried to integrate NGINX code inside my application but that didn't work,
i tried to programmatically control NGINX service from my application code ( check if the service is running and if it is not then run the service),
but that had it's problems too !

eventually after 3 days ! i get rid of NGINX and started to integrate C# asp.net webapi selfhost (http://www.asp.net/web-api/overview/older-versions/self-host-a-web-api) into my application using C++ CLI ( i was on windows ).

that was my experience ( maybe i was not a good programmer ), but C++ CLI and C# webapi really worked,
it was easy to integrate C# assembles into my native C++ application and the asp.net webapi was stable enough not to cause more troubles.
Feb 20, 2015 at 6:58 AM
This is pretty surprising that casablanca doesn't offer a way to accesss http_listener to access the server locally. Now my clients have clearly said that they don't want any CLR or .NET framework to be used, because most of the consumers in his network still use Windows XP, therefore doens't have .NET framework in their PCs.
Feb 25, 2015 at 4:10 PM
Guys,

You have to have IIS enabled, and be running the listener as an administrator.

Damien
Feb 25, 2015 at 7:47 PM
@Damien: >> Why do you need IIS? http_listener in windows is implemented using httpsys API. Why would you need IIS? What is IIS role here?
Feb 25, 2015 at 10:51 PM
I'm not at my system right now, but I'm pretty sure we had to enable IIS to be able to access the service from external IP addresses. Maybe Steve or someone else can jump in and provide official guidance.

Damien
Coordinator
Feb 25, 2015 at 11:28 PM
I don't believe that you need to have IIS enabled to access from an external IP address. Variants on this discussion have come up quite a bit. As 000golabi mentions earlier in this thread, the main purpose of this library is for connecting to and consuming RESTful services.

For the http_listener on Windows, we build directly on top of the Windows HTTP Server API. So for listening to external requests you will have to follow the same rules. Specifically you need administrative privileges or have to have an admin make a reservation on a portion of the desired URI. See the HTTP Server API for more documentation.

Steve
Feb 26, 2015 at 5:01 PM
What is server? is it defined by me, or it is something that cpprest has?

I have a somehow similar problem: I want to create a status page for my application. I have just posted the thread today, any help please?
Feb 26, 2015 at 6:25 PM
Following up on Steve's response above, I disabled IIS on my test machines and the Casablanca-based services we have still work from external IPs (on Win 7 and 8.1). So:

1) You don't need IIS running for Casablanca-based listener services to work on Windows.
2) To provide services to external IPs, you need to be listening on http://*:xxxxx where xxxxx is your port number.
3) Your listener needs to be running with admin privileges, or have the reservation described above. There's more information on reservations here:

https://casablanca.codeplex.com/discussions/532385

4) You need to open up your firewall for the port(s) you're using. You need an incoming port rule for that, not an incoming program rule on a specific port.

Damien