Android Basics (v) Network programming

Source: Internet
Author: User

Android's network programming can generally be divided into two types: socket-based, HTTP-based.

First, socket and HTTP

The socket encapsulates the TCP/IP protocol, and the TPC/IP protocol is the Transport Layer protocol that mainly addresses how data is transmitted over the network. Socket communication mode is when the server side with the client to establish a socket connection, the server can directly transfer data to the client. (to establish a socket connection: A socket connection is required at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket. The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement. )

HTTP is the Application layer protocol, HTTP is the use of TCP between the server and the client to transfer information between the Protocol, mainly to solve how to package the data. HTTP communication means that the server needs to wait until the client sends a request to send the data back to the client, so the client periodically sends a connection request to the server, not only to remain online, but also to "ask" the server if there is new data, and if so, pass the data to the client.

When we transmit data, we can only use the (Transport Layer) TCP/IP protocol, but then, if there is no application layer, it will not be able to identify the data content, if you want to make the transferred data meaningful, you must use to the Application layer protocol, the application layer protocol, such as HTTP, FTP, Telnet, etc.

Therefore, the HTTP communication method can be seen as a way to encapsulate the transmitted data in the socket communication mode. The TCP/IP protocol supported by the socket communication is equivalent to the lorry on the communication Highway, which is responsible for the transport task, while HTTP is equivalent to the goods carried on the lorry and is responsible for packaging the data to be transmitted as a complete cargo.

Second, the socket communication programming implementation

Android Basics (v) Network programming

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.