[Windows socket + HTTP Server Client]

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.