Windows Socket + HTTP Server Client
WinsockWindows Socket Standard.1. HTTP protocol:
HTTP is a client/server-based request and response protocol.
Request: the client initiates a request to the server, specifying the resources to be obtained from the server. The request contains the protocol header, indicating the client's processing capability, such as the file type that can be processed, Supported languages, and encoding methods.Response: after receiving a request from the client, the server parses the request, constructs a response, and sends it to the client. The response also contains the protocol header, indicating the server-related information.2. Simple HTTP server and client:
In reality, the HTTP protocol has certain complexity in consideration of various requirements. Here we only implement a simple HTTP server and client, focusing on understanding the working principles of the HTTP protocol.In Winsock programming, the client sends a piece of data (that is, a request) to the client through socket, which contains the resources requested by the client (that is, files ).After receiving the data, the client processes the data (that is, parses the URL), extracts the resource name requested by the client, and finds the server Resource Based on the Resource Name, after processing resources and other information (that is, the response), send them to the client.3. essence of the HTTP server and client:
The HTTP protocol is built on the socket. Essentially, two programs send data to each other through the socket. The HTTP Protocol specifies the format of the data sent by the sender and how the receiver uses the accepted data. The implementation of the HTTP server and client is reflected in the processing of sending and receiving data by sending and receiving data through dual-sending. In the simplest example, the client sends a "GET 1.html" data to the server. After receiving the data, the server interprets the "GET 1.html" ghost file and writes it to the data sent by the server.
4. Test the knife:Run the server in VC6.0, and then open a client running VC6.0.
Running effect:Common browsers are also clients. Obviously, our clients simply print html file content, and the browser processes HTML files and displays them according to html rules.
Servers and clients refer to Winsock network programming meridianClient Program:Server program: