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
  • 相关阅读:
    day-11函数的形参与实参
    day-10初级函数
    .检查用户名是否使用接口
    04.vue发送短信逻辑
    03.celery发送短信接口
    02.celery配置与基本使用
    Celery介绍
    python爬虫与Django框架vue交互的前后端代码详情(励志人生网实例)
    爬虫找工作之面试题(2)
    爬虫找工作之面试题(1)
  • 原文地址:https://www.cnblogs.com/anmoon/p/1805671.html
Copyright © 2011-2022 走看看