Differences between Android HTTP connections and TCP connections

Source: Internet
Author: User
Tags domain name server

Recently, I have seen that a certain architecture uses TCP connections instead of HTTP connections. I realized that I don't know the difference between the two, so I can check the information to complete the knowledge.

Refer to the following Blog content:

Http://blog.csdn.net/yangzl2008/article/details/7366428

Http://blog.csdn.net/xyylchq/article/details/7660915

Http://blog.csdn.net/xuyide54321/article/details/7075222

Use your own words to summarize:

The question is the difference between the android HTTP connection and the TCP connection, because I am concerned about the use of the android environment, in fact, whether it is Android or PC, it should be the same.

HTTP is the application layer protocol, TCP is the network layer protocol, and the application layer is located on the top layer of TCP in the TCP/IP layer-4 architecture. There are two methods to establish an HTTP connection:

DefaultHttpClient http = new DefaultHttpClient();HttpGet method = new HttpGet(url); HttpResponse response =http.execute(method);
URL url = new URL(uri);HttpURLConnection connection = (HttpURLConnection)url.openConnection();connection.connect();

When implementing TCP connections, you must use socket (socket IP + port number)

Socket s = new Socket("localhost", 12345); 

I think the difference can be seen from the implementation of these two connections. The HTTP connection needs to specify the resource URL, and the requested application does not know the Server IP address, although the Domain Name Server also needs to resolve the domain name into an IP address, it does not fall into the scope of application concern and should be done by the network layer. Therefore, an HTTP connection is a stateless short connection. If you request other data, you need to establish a new connection. The server knows the existence of the client only after the client sends a request to the server.
When implementing TCP connections, you must specify the IP address and port number to establish a connection with the target host through three handshakes. The connection is maintained until one Party proposes to cancel the connection and closes the connection through four handshakes. The socket supports the TCP/UDP protocol. If the TCP protocol is used, the socket connection is a TCP connection. The Application Scenario mentioned in this paper is to establish a connection between a mobile phone and a server on the cloud. To maintain a connection and specify the connection establishment time, it is most appropriate to use a TCP connection in this scenario. 3G networks do not support end-to-end TCP connection. Because it is in client-server mode, end-to-end communication of mobile phones must be achieved through the assistance of cloud servers.

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.