Problem with connecting to HttpListener

Hi there

I am facing a strange problem. I have a dial-up connection and I developed a webpage that recevies the incoming httprequests. Then I used HttpListener to make like a Web server. however, when I try to connect to my server from the same machine (using localhost) it receives but when I try this from outside it fails. The code is shown below:

(I put a break point at the beginning of the second method and no connection is going there)

private void button5_Click_1(object sender, EventArgs e)

{

HttpListener listener = new HttpListener();

listener.Prefixes.Add("http://213.166.151.30:8081/WebSite/Default.aspx/");

listener.Start();

listener.BeginGetContext(new AsyncCallback(OnGetContext),listener);

}

void OnGetContext(IAsyncResult result)

{

HttpListener listen = (HttpListener)result.AsyncState;

HttpListenerContext context = listen.EndGetContext(result);

HttpListenerRequest request = context.Request;

HttpListenerResponse response = context.Response;

Stream stream2 = response.OutputStream;

response.StatusCode = 100;

response.StatusDescription = "Continue";

byte[] data2 = new byte[1024];

data2 = Encoding.ASCII.GetBytes("\r\n");

stream2.Write(data2, 0, data2.Length);

stream2.Flush();

stream2.Close();

response.Close();

}

Regards

Salman




Answer this question

Problem with connecting to HttpListener

  • Austin Milbardge

    If you are running Windows XP have you added TCP port 8081 to the firewall exception list

  • Problem with connecting to HttpListener