Why different behavior of localhost and

Feb 17, 2014 at 11:58 PM
Edited Feb 17, 2014 at 11:59 PM
Why does localhost:3901 work ok, but doesn't work (hangs browser before timing out)? Shouldn't they operate the same way? I'm using Windows 8.1. I'm new so maybe I'm missing something obvious.
    m_listener = web::http::experimental::listener::http_listener(L"http://localhost:3901");
No work:
    m_listener = web::http::experimental::listener::http_listener(L"");
Hosts file fragment:
# localhost name resolution is handled within DNS itself.
#       localhost
#   ::1             localhost
Feb 18, 2014 at 1:20 AM
From our tests, we did not find any problems. Can you post your complete code to help us repro.

Feb 19, 2014 at 3:18 AM
Edited Feb 20, 2014 at 12:45 AM
Something is really strange on my system. Maybe it's related to this issue, maybe not. I'm posting a uri issue on a new thread.

Update: 19-Feb-2014: My bad. I had intermingled the release .lib file with the debug .dll file.
Feb 20, 2014 at 12:42 AM
Edited Feb 20, 2014 at 12:43 AM
I tracked down the error. Here's the error message:

Access denied: attempting to add Address ''. Run as administrator to listen on an hostname other than localhost, or to listen on port 80.

Indeed, running the program as administrator works.

  1. Why is it necessary to run as administrator?
  2. Seems odd that doesn't work but http://localhost:3901 does work. Why is that?
  3. Is the need to run in administrator mode documented anywhere?
  4. What are my options to enable the program to run in user mode?
  5. Why hasn't this issue been raised before? I'm running Windows 8.1 64-bit.
  6. Does this issue also effect Linux?
Feb 20, 2014 at 10:51 PM
Hi BSalita,

What is going on here is how Windows works with HTTP URI namespace reservations. Take a look at these two msdn pages, one explaining for the HTTP Server API (which we build on) and another describing the same in the context of WCF also built on the HTTP Server API.

Basically by default all non administrator users don't have any HTTP URI namespace reservations. Localhost is special, but doesn't actually listen allowing external machines to connect. Only an administrator can setup and reserve a URL HTTP namespace. The idea is that this is usually done during installation or setup of your program on a user's machine, when administrator privileges are already required.

There are several ways this can be done, the command line tools netsh or HttpCfg.exe can be used. Also the Windows API HttpSetServiceConfiguration.

Feb 21, 2014 at 2:35 AM
Thanks for your help. I've figured out the netsh syntax for making a http reservation. I'm documenting here and on StackOverflow.

You must have Administrator privileges to add or delete. You must have a trailing / at end of url parameter.

To add a reservation:
netsh http add urlacl url= user=%USERNAME%

To show reservations:
netsh http show urlacl

To delete a reservation:
netsh http delete urlacl

Anyone know how to get wildcarding of ip:port addresses to work. NONE of the following seem to work: url=http://+:3901/ or url= or url=http://*:3901/
May 21, 2014 at 1:45 PM
Anyone know how to get wildcarding of ip:port addresses to work. NONE of the following seem to work: url=http://+:3901/ or url= or url=http://*:3901/
May 23, 2014 at 7:31 AM worked for me on RHEL. earlier firewall was blocking.

To know whether any firewall setting on HTTP do the following command

iptables -L | grep -i http

if any entry is there, then you make sure your iptables service is up and running.

to view the current status
service iptables status

to start the service
service iptables start