C # httplistener error if remote ip

I created an httplistener and only works with localhost as prefix. It shows error if I change it to the IP address of the remote server.

Here's the code:

 HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://*:8080/");  // I need localhost replaced with remote ip
        while (true)
            // Wait for a client request:
            HttpListenerContext context = listener.GetContext();

            // Respond to the request:
            string msg = "You asked for: " + context.Request.RawUrl;
            context.Response.ContentLength64 = Encoding.UTF8.GetByteCount(msg);
            context.Response.StatusCode = (int)HttpStatusCode.OK;

            using (Stream s = context.Response.OutputStream)
            using (StreamWriter writer = new StreamWriter(s))


This is the web client:

   using (WebClient wc = new WebClient())        // Make a client request.
                      ("http://"my public ip"(on  my router):8080/lg.txt"); //port forwarding is set


It only works if I change "my public ip" to my local ip Any ideas?


source to share

2 answers

Is Windows Firewall enabled? Try disabling it and see if that helps. You may need to actually disable the Windows Firewall service (in your local services list).



First, check your firewall. This is probably most likely http.sys, which is used by the HttpListener - you must make the prefix available to the account via "netsh". You can verify this by running as an elevated administrator account in a nutshell - if that works, it might be a http.sys permissions issue.



All Articles