Summarize the differences between socket and http

伊谢尔伦
Release: 2023-03-07 20:30:01
Original
7518 people have browsed it

http related introduction

HTTP protocol is the Hypertext Transfer Protocol (Hypertext Transfer Protocol), which is the basis of Web networking and one of the protocols commonly used in mobile phone networking. 1. The HTTP protocol is an application built on the TCP protocol.

The most significant feature of HTTP connections is that each request sent by the client requires the server to send back a response. After the request is completed, the connection will be actively released. The process from establishing a connection to closing the connection is called "a connection".

1) In HTTP 1.0, each request from the client requires the establishment of a separate connection. After processing this request, the connection is automatically released.

2) In HTTP 1.1, multiple requests can be processed in one connection, and multiple requests can be overlapped. There is no need to wait for one request to end before sending the next request.

Since HTTP will actively release the connection after each request, the HTTP connection is a "short connection". To keep the client program online, you need to continuously initiate connection requests to the server. The usual practice is that there is no need to obtain any data, and the client keeps sending a "keep connected" request to the server at regular intervals. After receiving the request, the server replies to the client, indicating that it knows that the client " Online". If the server cannot receive the client's request for a long time, the client is considered "offline". If the client cannot receive the server's reply for a long time, the network is considered disconnected.

What are TCP/IP and UDP?

TCP/IP (Transmission Control Protocol/Internet Protocol) is Transmission Control Protocol/Internet Protocol. It is an industry standard protocol set designed for wide area networks (WANs).

UDP (User Data Protocol, User Datagram Protocol) is a protocol corresponding to TCP. It is a member of the TCP/IP protocol suite.

The previous introduction is whatsocket is and some of its functions. Socket is the cornerstone of communication and the basic operating unit for network communication that supports the TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process and contains five types of information necessary for network communication: the protocol used for connection, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol of the remote process. port. When the application layer communicates data through the transport layer, TCP will encounter the problem of providing concurrent services to multiple application processes at the same time. Multiple TCP connections or multiple application processes may need to transmit data through the same TCP protocol port. In order to distinguish different application processes and connections, many computer operating systems provide socket (Socket) interfaces for applications to interact with the TCP/IP protocol. The application layer can use the Socket interface with the transport layer to distinguish communications from different application processes or network connections to implement concurrent services for data transmission. The following figure shows the position of Socket:

Summarize the differences between socket and http


The main difference between Http and Socket

Socket implements the physical connection between the server and the client and performs data transmission. There are two main protocols: TCP/UDP. Socket is at the transport layer of the network protocol.

TCP: Transmission Control Protocol, a connection-oriented protocol, stable and reliable. Before the client and server can exchange data with each other, a TCP connection must be established between the two parties before the data can be transmitted.

UDP: Broadcast data transmission. UDP does not provide reliability. It only sends the datagrams passed to the IP layer by the application, but there is no guarantee that they can reach the destination. Because UDP does not need to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as timeout retransmission, the transmission speed is very fast.

Advantages:

1. The transmission data is byte level, the transmission data can be customized, and the data volume is small. Corresponding mobile terminal development, low mobile phone cost

2. Short data transmission time, high performance

3. Suitable for real-time information interaction between C/S

4. Yes Encryption, high data security

Disadvantages:

1. The transmitted data needs to be parsed and converted into application-level data

2. High requirements for developers' development level

3. Compared with Http protocol transmission, the amount of development is increased

Http requests mainly include http protocol, soap protocol based on http protocol, and common http data Request methods include get and post, web service

Advantages:

1. Easy to use based on application-level interface

2. Required development level Not high, strong fault tolerance

Disadvantages:

1. Slow transmission speed and large data packets.

2. If real-time interaction is implemented, the server performance will be under great pressure

3. Data transmission security is poor

Comparison of applicable scenarios:

Socket applicable scenarios: online games, bank interaction, payment.

http applicable scenarios: company OA services, Internet services.

【Recommended related tutorials】

1. "php.cn Dugu Jiujian (4)-php video tutorial"

2. #php programming from entry to master a complete set of tutorials

The above is the detailed content of Summarize the differences between socket and http. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!