Summarize the differences between sockets and HTTP

Source: Internet
Author: User
Tags php programming
HTTP Related Introduction

The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol.

The most notable feature of an HTTP connection is that each request sent by the client requires a server loopback response, and the connection is actively released after the request has ended. The process from establishing a connection to closing a connection is called a "one-time connection."

1) in HTTP 1.0, each request from the client requires a separate connection to be established, and the connection is automatically freed after the request is processed.

2) in HTTP 1.1, multiple requests can be processed in a single connection, and multiple requests can overlap, without waiting for a request to end before sending the next request.

Because HTTP is actively releasing the connection after each request ends, the HTTP connection is a "short connection", which requires constant connection requests to the server to maintain the client program's online status. As a general practice, there is no need to obtain any data immediately, and the client will keep a "keep-connected" request to the server at regular intervals, and the server responds to the client after receiving the request, indicating that the client is "online". If the server can not receive the client's request for a long time, it is considered that the client "offline", if the client cannot receive a reply from the server for a long time, it is considered that the network has been disconnected.

What is TCP/IP, UDP?

TCP/IP (transmission Control protocol/internet Protocol) is a protocol/inter-network protocol, an industry-standard set of protocols designed for wide area networks (WANs).

UDP (User data Protocol, Subscriber Datagram Protocol) is the protocol that corresponds to TCP. It is a part of the TCP/IP protocol family.

Here is what the socket and some of its functions, socket is the cornerstone of communication, is to support the TCP/IP protocol network communication basic operating unit. It is an abstract representation of the endpoint in the network communication process and contains five kinds of information that must be used for network communication: the protocol that the connection uses, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol port of the remote process. When the application layer communicates data through the transport layer, TCP encounters a problem that provides concurrent services for multiple application processes at the same time. Multiple TCP connections or multiple application processes may require data to be transmitted over the same TCP protocol port. To differentiate between different application processes and connections, many computer operating systems provide a socket (socket) interface for applications interacting with the TCP/IP protocol. The application layer can communicate with the transport layer through the socket interface, differentiate the communication from different application processes or network connections, and realize the concurrent service of data transmission. You can see where the socket is located:


The main difference between Http and Socket

The Socket implements a physical connection between the server and the client and transmits data. There are mainly tcp/udp of two protocols. The socket is in the transport layer of the network protocol.

TCP: Transmission Control Protocol, connection-oriented protocols, stable and reliable. Before the customer and the server Exchange data with each other, a TCP connection must be established between the two parties before the data can be transferred.

UDP: Broadcast data transmission, UDP does not provide reliability, it simply sends the application to the IP layer of the datagram sent out, but does not guarantee that they can reach the destination. Because UDP does not have to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as time-out retransmission, the transmission speed is very fast.

Advantages:

1. Transfer data is byte-level, transfer data can be customized, the amount of data is small. Corresponding mobile development, low mobile phone costs

2. Short data transfer time, high performance

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

4. Can be encrypted, high data security

Disadvantages:

1. Need to parse the transmitted data into application-level data

2. High level of developer development requirements

3. Increased development volume compared to HTTP protocol transmission

HTTP requests mainly have HTTP protocol, HTTP protocol-based SOAP protocol, common HTTP data request method has get and Post,web service

Advantages:

1. Application-level-based interface ease of use

2. The required development level is not high, the fault tolerance is strong

Disadvantages:

1. The transmission speed is slow, the packet is large.

2. If real-time interaction is achieved, the server performance pressure is high

3. Poor data transfer security

Comparison of applicable scenarios:

Socket Application Scenario: Online game, bank interaction, payment.

HTTP applicable scenario: Company OA service, Internet service.

"Related tutorials Recommended"

1. "Php.cn lonely Nine Cheap (4)-php video Tutorial"

2. PHP programming from getting started to mastering the full set of tutorials

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.