使用的HttpListener创建自定义网站,网址为我的IP地址 [英] using httpListener to create custom website with URL as my IP-Address

查看:921
本文介绍了使用的HttpListener创建自定义网站,网址为我的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个URL一个网站作为我的 IP地址 [例如:192.X.X.X]

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.

我用下面的code要做到这一点![它只是一个基本的code,没有线程]

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

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);

          }
     }
}

问题是,我不知道在 IP地址通过这些人会访问。

它完美地展示了回应你好,当我使用的http://本地主机/ 作为网址

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

IP地址将其他人使用,使他们可以访问我的简单的网站。

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

我已经尽了IP地址的浏览器,但它不工作

I have tried my IP-address in the browser but it doesnt work.

推荐答案

的问题是,我指的是一个专用网络地址这是当地网​​络键,不能被任何人的之外进行访问的专用网络 ..

The problem was that I was referring to a private network address which are local to the network and cannot be accessed by anyone outside that private network..

这些都是在专用网络使用,因此与该地址系统不能是服务器或主机的网站 IP地址的范围。

These are the range of ip-address that are used in private network and so systems with this address cannot be a server or host a website..

10.0.0.0 to 10.255.255.255

172.16.0.0 to 172.31.255.255

192.168.0.0 to 192.168.255.255

您应该使用公网地址。

这篇关于使用的HttpListener创建自定义网站,网址为我的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆