What is web server?
Baidu encyclopedia explains this:
Web Server WEB Server WWW
The Web server can parse the HTTP protocol (handles. When the Web server receives an HTTP request, it returns an HTTP response (response), for example, sending back an HTML page. In order to process a request, the Web server can respond to a static page or image, perform a page Jump (redirect), or send a dynamic response (dynamic response) to some other programs, such as CGI scripts, JSP (assumerver Pages) scripts, servlets, ASP (Active Server Pages) scripts, server-side) javaScript, or some other server-side technologies. Regardless of their purpose, these server-side programs usually generate an HTML response (response) for browsers to browse.
In general, Web server transfer (serves) pages allow browsers to browse. However, the application server provides client applications with the call method ). Specifically, you can say that the Web server specifically processes HTTP requests, but the application server uses many protocols to provide business logic for applications ).
Common web Server
We often use web services such as IIS and tomcat. During network communication, we will also use socket, or even implement HTTP Communication Based on socket, but let's take a look at the simpler implementation.
What can we do?
IIS is very powerful and has complete functions. Our goal is not to make a web server that is the same as it. It serves our development and architecture based on this concept.
Features and usage:
For example, when we need to communicate with multiple applications in our software.
Dedicated functions bring higher efficiency. For example, we only process the display of a certain page. We have seen the router Management page in the route, that is, a lightweight small web server implementation, which can not be placed in windows + iis;
Embedded windows applications. For example, we want to embed webBrower in winform to use it for some applications.
Our implementation
HttpListener Class Based on. net FrameworkTo process the http protocol, we only need to write a processing class based on it.
= = Thread( ThreadStart( (==== (request.HttpMethod == (request.HttpMethod == +[] buffer = Encoding.UTF8.GetBytes(= +[] res = Encoding.UTF8.GetBytes(
How to use it?
1. Write a class that inherits from the Servlet class and implement the specific business logic here.
2. Copy the code in the main method and start httpListener in a proper way.
Reference: http://wenku.baidu.com/link? Url = Response
Http://msdn.microsoft.com/zh-cn/library/system.net.httplistener (v = vs.110). aspx