I created a httplistener and it works only with localhost as a prefix. It show an error if I change it to a remote server ip.
Here’s the code:
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:8080/"); // I need localhost replaced with remote ip
listener.Start();
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))
writer.Write(msg);
}
listener.Stop();
THis is the web client:
using (WebClient wc = new WebClient()) // Make a client request.
wc.DownloadString
("http://"my public ip"(on my router):8080/lg.txt"); //port forwarding is set
MessageBox.Show("received");
It works only if I change “my public ip” to my local ip
Any ideas?
Is your Windows Firewall on? Try disabling it and see if that helps. You may need to actually disable the Windows Firewall service (in your local services list).