Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
I want to create a website with URL as my IP-address[ex: 192.X.X.X]

That website would respond with a "HELLO THERE" message to any user who accesses my URL.

I use the following code to do this![its just a basic code with no threading]

C#
class listenToHTTP
{
    HttpListener _listner;
    public void start()
    {
        _listner = new HttpListener();
        _listner.Prefixes.Add("http://localhost/");//default port 80
        _listner.Start();
    }
    public void process()
    {
        while (true)
        {
            HttpListenerContext context = _listner.GetContext();
            byte[] output = Encoding.ASCII.GetBytes("HELLO THERE");
            context.Response.ContentEncoding = Encoding.ASCII;
            context.Response.ContentLength64 = output.Length;
            context.Response.OutputStream.Write(output, 0, output.Length);

        }
    }
}

The problem is that i dont know the IP-address through which anyone would access.

It perfectly shows the response "HELLO THERE" when I use http://localhost/ as URL.

But what IP-address would other people use so that they can access my simple website.

I have tried my IP-address in the browser but it doesnt work.
Posted
Updated 25-Feb-12 7:09am
v2
Comments
Sergey Alexandrovich Kryukov 25-Feb-12 18:22pm    
"It does not work" is not informative.
--SA
Sergey Alexandrovich Kryukov 25-Feb-12 18:31pm    
Are you sure you tried to use your IP address from the computers in the same local network, because you IP address suggest your server has only a local network access?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900