zoukankan      html  css  js  c++  java
  • 最简单的http服务器(C#)

    using System;   using System.Collections.Generic;   using System.Text;   using System.Net;   using System.Net.Sockets;      namespace http_server   {    class Program    {    static void Main(string[] args)    {    int port = 80;    int len = 0;    TcpListener server = new TcpListener(port);       server.Start();       Console.WriteLine("server start port[{0}]", port);       while(true)    {       Socket client = server.AcceptSocket();       byte[] buf = new byte[1024];    len = client.Receive(buf);       Console.WriteLine("read len[{0}] data:", len);    Console.WriteLine(Encoding.ASCII.GetString(buf));       string abc = @"HTTP/1.0 200 OK\nContent-Type: text/html\n\n    Welcome   

    Welcome!

       The current time at this device is {0}

       ";       DateTime dt = DateTime.Now;    string nnn = string.Format(abc, dt.ToString());    len = client.Send(Encoding.ASCII.GetBytes(nnn));       Console.WriteLine("write len[{0}] data:", len);    Console.WriteLine(abc);       client.Close();    client = null;    }       }    }   }         ======================================   程序启动后在浏览器中输入:http://127.0.0.1/   回车后即可看到响应如下:   Welcome!

    赋予程序生命,还我自由河山!~ --CosMosGhost
  • 相关阅读:
    继承(二)
    抽象和封装(一)
    系统优化——建立linux回收站机制
    kvm-web管理工具webvirtmgr
    云产品类别及其特点(转)
    zabbix通过agent监控linux主机
    zabbix通过snmp监控linux主机
    zabbix通过snmp监控windows主机
    zabbix的安装
    运维各技术方向及其成熟的技术分支
  • 原文地址:https://www.cnblogs.com/anmoon/p/1805671.html
Copyright © 2011-2022 走看看