I. Implementation principle
- HTTP requests are TCP communications, so the first step is to instantiate the QTcpServer class listening port and bind the newConnection signal slot.
- Once there is a new connection, it is handed over to a special unpacking class for processing, and the corresponding data is unpacked. If the HTTP request has a specific header data, such as whether it needs to be saved, it is taken out and the application is parsed.
- Sending and receiving data interaction is actually the interaction of the QTcpSocket communication object, but the sending and receiving data with the corresponding header data.
- To reply to web page data, simply send the HTML data of the web page to the requesting object.
Two, functional characteristics
- Support multiple client connections at the same time, 100 no pressure.
- You can set whether HTTP requests are long or short connections. The default is long connections.
- Supports multiple reply data formats, including web content, JSON data, and so on.
- The server example contains both file reply reading and database reply reading.
- Support 8 color schemes (dark, gray black, dark green, light yellow, dark blue, dark black, dark blue, default).
- The client can specify the request address, and the server can specify the network card and port to listen.
- All requests and connections are counted, and the IP and port numbers for all online requests are displayed in the table.
- Can provide a simple web page configuration service, including interaction, as the device web configuration.
- Can be expanded freely to add permission verification, etc., as an HTTP request server.
- Pure Qt implementation, code framework clean, annotation complete, support any Qt version, any compiler, any operating system.
Three, effect drawing
4. Experience address
- Experience address: pan.baidu.com/s/1ZxG-oyUK… Extraction code: o05Q Name: bin_httpServer.zip
- Domestic site: gitee.com/feiyangqing…
- International site: github.com/feiyangqing…
- Profile: blog.csdn.net/feiyangqing…
- Zhihu homepage: www.zhihu.com/people/feiy…