Communication protocols in Android

Source: Internet
Author: User

One, TCP/IP Protocol (Transport layer Protocol)

1. Socket and ServerSocket

Socket is the application layer and TCP/IP protocol cluster communication between the intermediate abstraction layer, socket is a set of interfaces, in design mode, socket design is the façade mode, it is the complex TCP/IP protocol cluster content hidden behind the socket interface, the user does not need to care about the implementation of the Protocol, Just use the interface provided by the socket.

There are two types of sockets, one for connection-oriented TCP application services and one for non-connected UDP (User Data package) applications. The popular understanding is that the TCP method is called (connectivity), the UDP method is to send text messages (no connection).

The ServerSocket class is a listening service that is used to listen to the computer at the specified port, and the object that is transmitting the data is the socket object.

ServerSocket generally only used to set the port number and monitoring, the real communication is the server-side socket and client socket, after the ServerSocket to accept, will be the active transfer.

See more: http://www.cnblogs.com/mareymarey111/archive/2011/12/08/2280253.html

Second, UDP Protocol (Transport Layer Protocol)

The full name of the UDP protocol is the User Datagram Protocol, which is used in the network as the TCP protocol to process packets and is a non-connected protocol. In the OSI model, the fourth layer, the transport layer, is in the upper layer of the IP protocol. UDP has the disadvantage of not providing packet grouping, assembling, or sorting packets, that is, when the message is sent, it is not possible to know whether or not it arrives safely and completely. UDP is used to support network applications that need to transfer data between computers. A large number of client/server mode network applications, including the network video conferencing system, require the use of UDP protocol. UDP protocol has been used for many years since its inception, although its original glory has been obscured by some similar protocols, but even today, UDP is still a very practical and feasible network Transport layer protocol.

The main function of the UDP protocol is to compress the network data traffic into the form of packets. A typical packet is a transmission unit of binary data. The first 8 bytes of each packet are used to contain the header information, and the remaining bytes are used to contain the specific transmitted data.

In order to recognize multiple destination addresses on a given host while allowing multiple applications to work on the same host and be able to send and receive packets independently, the User Datagram Protocol UDP is designed.

The use of UDP protocol includes: TFTP, SNMP, NFS, DNS, BOOTP

UDP uses the underlying Internet Protocol to transmit messages, providing unreliable, non-connected packet transfer services as IP. It does not provide message arrival confirmation, sequencing, and flow control functions.

1, Datagramsocket and Datagrampackage

Datagramsocket on behalf of the UDP protocol Socket,datagramsocket itself is just a pier, not maintenance state, can not generate IO stream, its only role is to receive and send datagrams,

For a detailed explanation please see: http://blog.csdn.net/jiangxinyu/article/details/8161044

Datagrampacket to represent datagrams, the data received and sent by Datagramsocket is done through Datagrampacket objects.

For a detailed explanation please see: http://blog.csdn.net/oney139/article/details/8063067

Third, HTTP protocol (Application layer protocol)

The HTTP protocol is an application-layer protocol, and HTTP is an acronym for Hypertext Transfer Protocol (Hypertext Transfer Protocol). HTTP can transfer data between the client and the server through the TCP protocol of the Transport layer. The HTTP protocol is primarily used for data exchange between Web browsers and Web servers. when we use IE or Firefox to browse the Web or download Web resources, by entering Http://host:port/path in the Address bar, the first 4-letter HTTP is equivalent to notifying the browser to use the HTTP protocol to communicate with the server determined by host.

See more: http://blog.csdn.net/xijiaohuangcao/article/details/6729277

Access network resources using JDK httpurlconnection and Apache HttpClient in Android

1, HttpURLConnection

Java applications need to access network resources for the specified URL address directly through the HttpURLConnection class, providing a way to post and get.

For more details, see: http://blog.csdn.net/loovejava/article/details/12950129

2, HttpClient (Google integrated Apache HTTP protocol)

Android,ANDROIDSDK integrates Apache's httpclient module to provide efficient, up-to-date, feature-rich support for the HTTP protocol toolkit, and it supports the latest versions and recommendations of the HTTP protocol.

For more details, see: http://blog.csdn.net/litton_van/article/details/6544086

The difference between httpurlconnection and httpclient is that the HttpClient encapsulates the method and module of HTTP protocol request, which is convenient for quick integration. Explanation: http://blog.csdn.net/micaixiaoduanku/article/details/39958615

Third, Android calls WebService communication

Web Services (Web service) is a software system that supports the interoperability of different machines between networks, a self-contained, self-describing, and modular application that can be described, published, and invoked in the network as a network-based, distributed, modular component.
WEB services are built on the basis of common protocols, such as HTTP, SOAP, UDDI, WSDL, and so on, which have no inclination to choose the operating system, programming language and object model, and therefore have strong vitality.
the advantage of Web services is that it provides interoperability between different application platforms, which enables component-based development and WEB integration to work best. It is based on the HTTP protocol, the call request and the response message can pass through the firewall, do not need to change the firewall settings, so as to avoid the use of special ports to communicate with the problem of unable to cross the firewall.

Simply put: by using WebService, we are able to invoke methods on the remote server just like local methods. We don't need to worry about whether the remote method is written in Java or written in PHP or C #, and we don't need to care whether the remote approach is based on UNIX or Windows, which means WebService is not related to the platform or language.

Android calls WebService mainly: SOAP protocol and WSDL protocol

1. SOAP protocol

SOAP, Simple Object access Protocol, is a lightweight, simple, XML-based protocol that is designed to exchange simple protocols for formatting and curing information in a distributed environment. In other words, to communicate, data access transmission, you must rely on a certain protocol, and SOAP is the WebService communication is dependent on a protocol. There are two versions of the SOAP protocol currently in use: SOAP 1.1 and SOAP 1.2.

Note: Android uses the SOAP protocol call WebService, the call is the server method, pass the parameters to be transmitted sequentially, the configuration of the version number is correct, the reader can refer to the details of their own. See annex

Detailed use: http://blog.csdn.NET/long704480904/article/details/8636734

2. WSDL protocol

WSDL (Web Services Description Language, or Web Service Description language) is an XML language used to describe Web services, which describes the functions, interfaces, parameters, return values, and so on of Web services, so that users can bind and invoke services. It defines related actions and messages for a given Web service invocation and response in a language-neutral way.

Detailed use: http://blog.csdn.net/howlaa/article/details/21237331

Iv. Android uses WebView call server

Display Web pages directly using the WebView view component. Based on the development of WebView, Google has provided a Web browser based on Chrome-lite that allows you to surf the Web directly.

Communication protocols in Android

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.