0

I have an HTTP Server on a Win Console Application
I can access it in my LAN (and that's ok)
But adding the externalIP prefixe gives me an exception when running (not in the ide)
I have set port Forwarding in my router for port 4100
I have disabled my PC firewall
Exception:

System.Net.HttpListenerException (0x80004005): Parametro non corretto
in System.Net.HttpListener.AddAllPrefixes()
in System.Net.HttpListener.Start()
in HTTP_SERVER.Program.Main(String[] args) in C:\Users\ricca\Desktop\HTTP SERVER\HTTP SERVER\Program.cs:riga 34

Just in case:
Parametro non corretto --> incorrect parameter
riga 34 --> line 34 (where I call listener.Start();)

Code:

try
    {
        listener = new HttpListener();
        listener.Prefixes.Add("http://localhost:4100/main/");

        string externalip = new WebClient().DownloadString("http://icanhazip.com");
        Console.WriteLine(externalip);
     -->listener.Prefixes.Add("https://"+externalip+":4100/main/");

        listener.Prefixes.Add("http://"+ip+":4100/main/");
        Console.WriteLine("http://" + ip + ":4100/main/");
        listener.Start();

            //....
 }
catch(WebException eccezione_web)
 {
     Console.WriteLine(eccezione_web.Status);
 }
catch(Exception eccezione)
 {
     Console.WriteLine(eccezione.ToString());
 }

externalip is right

Every answer is welcome

Riccardo Raffini
  • 366
  • 7
  • 20

1 Answers1

0

This is not a programming problem.

The networking related classes do not care if the other end is on the same computer (loopback IP), on the same switch or on the Voyager 2 Probe*. If it works vs loopback IP, only network reasons might prevent it to work inside the network or through a router**.

Making certain there is a path is a Networking Problem, not a programming one. You are trying to access it from the Internet side of your router. That is not a trivial thing in the least. Indeed it goes into "how do I host a server in the Internet". Common workarounds include to "just use a VPN and learn to live without this function".

*Not 100% of course. You need pretty long timeouts for several lightmintues worth of distance. Wich might require some progamm setup.

**Small caveat stuff like the SQL servers default installations tend to be protected from being access anyway except loopback IP. A usual consideration for default passwords/useraccounts. Proper instances do not suffer that limitation.

Christopher
  • 9,634
  • 2
  • 17
  • 31