What is the difference between HTTP and socket connections in Android?

Source: Internet
Author: User

TCP connection:
The mobile phone can use the internet function because the mobile phone implements the TCP/IP protocol at the bottom layer, which enables the mobile phone to establish a TCP connection over the wireless network.
To establish a TCP connection, you must go through the "three-way handshake", as shown below:
The first handshake: the client sends a request to the server and waits for confirmation from the server.
The second handshake: the server responds to the client request and sends a response packet to the client.
Third handshake: the client sends a confirmation packet to the server after receiving the response packet from the server.

The package transmitted during the handshake does not contain data. After three handshakes are completed, the client and the server start to transmit data.
Once the TCP connection is established, the TCP connection will remain until either client or server closes the connection.
When you disconnect a TCP connection, both the server and client can initiate a request to disconnect the TCP connection. The disconnection process requires a four-way handshake"

HTTP connection:
HTTP is an application built on TCP. Different from TCP connections, a client requires a server for each request.
Returns a response. After the request ends, the connection is released. Because each HTTP request releases a connection, because the HTTP connection is a "short connection ",
To keep the client online, you must continuously initiate connection requests to the server. Therefore, in the development process, even if you do not need to obtain any data,
The client must also send a request to the server at intervals to ensure normal communication.

Socket connection:
Socket is the cornerstone of communication and the basic operation unit for network communication that supports TCP/IP protocol.
To establish a socket connection, you need a pair of sockets. One of the clients is running, the other is running, and the connection process between sockets is divided
Three steps: server listening, client request, and connection confirmation.

Related Article

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.