Write yourself a simple Web server that helps you understand the HTTP protocol better, let's take a look at a TcpListener Web server:
Class Program {static void Main (string[] args) {ipaddress address = Ipaddress.loopback;
IPEndPoint endPoint = new IPEndPoint (address, 49152);
TcpListener newserver = new TcpListener (endPoint); NewServer.
Start ();
Console.WriteLine ("Start listening ..."); while (true) {TcpClient newclient = NewServer.
AcceptTcpClient ();
Console.WriteLine ("Established Connection"); NetworkStream ns = newclient.
GetStream ();
System.Text.Encoding UTF8 = System.Text.Encoding.UTF8;
Byte[] Request=new byte[4096]; int lehgth = ns.
Read (Request, 0, 4096); String requeststring = UTF8.
GetString (Request);
Console.WriteLine (requeststring);
String statusline = "http/1.1 ok\r\n"; byte[] statuslinebytes = UTF8.
GetBytes (Statusline);
String responsebody = "
Run the program, then open the browser, in the browser window, enter the address of the server: http://localhost:49152, then return to see the data returned by the server.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/