Android communication protocol and Android communication protocol
I. TCP/IP protocol (Transport Layer Protocol)
1. Socket and ServerSocket
Socket is the intermediate abstraction layer for communications between the application layer and the TCP/IP protocol cluster. Socket is a group of interfaces. In the design mode, Socket is designed as the facade mode, it hides the content of the complex TCP/IP protocol cluster behind the Socket interface. You only need to use the interface provided by the Socket without worrying about the implementation of the Protocol.
There are two types of sockets: connection-oriented TCP Application Service and User Data Package-oriented UDP application service. In general, the TCP mode is called (connection), and The UDP mode is short message (no connection ).
The ServerSocket class is used to establish a listening service for listening to a specified port on the computer. The object for transmitting data is a socket object.
ServerSocket is generally only used to set the port number and listener. The Socket at the server end communicates with the Socket at the client end. After the ServerSocket accept, the initiative is transferred.
See http://www.cnblogs.com/mareymarey111/archive/2011/12/08/2280253.html for details
Ii. UDP protocol (Transport Layer Protocol)
UDP is a User Datagram Protocol. It is used to process data packets like TCP in the network. It is a connectionless protocol. In the OSI model, the fourth layer is the transport layer, which is the top layer of the IP protocol. UDP does not provide packet grouping, assembly, and sorting. In other words, when a packet is sent, it cannot know whether it is safe and complete. UDP is used to support network applications that need to transmit data between computers. Network applications in customer/Server mode, including network video conferencing systems, must use UDP protocol. UDP has been used for many years since its publication. Although its original glory has been concealed by some similar protocols, however, even today, UDP is still a very practical and feasible network transport layer protocol.
The main function of UDP protocol is to compress network data traffic into data packets. A typical data packet is the unit of binary data transmission. The first eight bytes of each data packet are used to contain header information, and the remaining bytes are used to contain specific transmitted data.
In order to identify multiple destination addresses on a given host, multiple applications can work on the same host and send and receive data packets independently, design the User Datagram Protocol (UDP.
UDP protocols include: TFTP, SNMP, NFS, DNS, and BOOTP.
UDP uses the underlying internet protocol to transmit packets. It provides unreliable connectionless data packet transmission services like IP addresses. It does not provide message arrival confirmation, sorting, and traffic control functions.
1. initramsocket and initrampackage
DatagramSocket represents the Socket of UDP protocol. mongoramsocket itself is only a dock and does not maintain the status. It cannot generate IO streams. Its only function is to receive and send data packets,
See: http://blog.csdn.net/jiangxinyu/article/details/8161044 for details
Mongorampacket represents a datagram. The data received and sent by mongorampacket is completed through the mongorampacket object.
See: http://blog.csdn.net/oney139/article/details/8063067 for details
Iii. HTTP protocol (application layer protocol)
HTTP is an application layer Protocol. HTTP is short for HyperText Transfer Protocol. HTTP can transmit data between the client and the server through the TCP protocol at the transport layer. HTTP is mainly used for data exchange between Web browsers and Web servers. When we use IE or Firefox to browse or download Web resources, input http: // host: port/path in the address bar, the four letters starting with http are equivalent to notifying the browser to use the HTTP protocol to communicate with the server specified by the host.
See http://blog.csdn.net/xijiaohuangcao/article/details/6729277 for details
Use HttpURLConnection of JDK and HttpClient of Apache in Android to access network resources
1. HttpURLConnection
Java applications directly use the HttpURLConnection class to access the network resources of a specified url address. The post and get methods are provided.
See http://blog.csdn.net/loovejava/article/details/12950129 for details
2. HttpClient (Google integrates Apache HTTP Protocol)
In Android, androidSDK integrates the HttpClient module of Apache to provide efficient, up-to-date, and functional support for the HTTP protocol toolkit. It also supports the latest versions and suggestions of the HTTP protocol.
See http://blog.csdn.net/litton_van/article/details/6544086 for details
The difference between HttpURLConnection and httpClient is that httpClient encapsulates http request methods and modules for fast integration and convenience. Details: http://blog.csdn.net/micaixiaoduanku/article/details/39958615
3. Android calls webService for communication
Web Services is a software system that supports interoperation between different machines in a network. It is a self-contained, self-described, and modular application, it can be described, published, and called in the network, and can be viewed as a network-based, distributed modular component.
Web Services are built on general protocols, such as HTTP, SOAP, UDDI, and WSDL. These protocols have no preference in the selection of operating systems, programming languages, and object models, therefore, it has a strong vitality.
The advantage of Web Services is that it provides interoperability between different application platforms, which makes the combination of component-based development and Web best. It is based on the HTTP protocol. Call requests and response messages can both pass through the firewall without changing the firewall settings. This avoids the problem that the firewall cannot be crossed when special ports are used for communication.
Simply put: By using WebService, we can call methods on the remote server just like calling local methods. We don't need to worry about whether the remote method is written in Java or in PHP or C #. We don't need to worry about whether the remote method is based on Unix or Windows, that is to say, WebService has nothing to do with the platform and language.
Android webservice calls mainly include the SOAP protocol and the WSDL protocol.
1. SOAP protocol
Simple Object Access Protocol (SOAP) is a lightweight, Simple, XML-based Protocol, it is designed to exchange simple protocols for formatting and solidification of information in a distributed environment. That is to say, for communication and data access and transmission, it must rely on a certain protocol, and SOAP is a protocol that is relied on in WebService communication. Currently, the commonly used SOAP protocol has two versions: SOAP 1.1 and SOAP 1.2.
Note: When Android uses the soap protocol to call webservice, it calls the server method. The transmitted parameters must be passed in sequence, and the configured version number must be correct, for more information, see. See Attachment
Usage: http://blog.csdn.NET/long704480904/article/details/8636734
2. WSDL Protocol
Web Services Description Language (WSDL) is an XML Language used to describe Web Services. It describes the functions, interfaces, parameters, and returned values of Web Services, this allows you to easily bind and call services. It defines operations and messages related to a given Web service call and response in a language-independent manner.
Usage: http://blog.csdn.net/howlaa/article/details/21237331
4. Android uses webview to call the server
Directly use the WebView component to display webpages. Developed based on WebView, Google has provided a chrome-lite-based Web browser that can directly browse the Web page.