UDP communication model example of Android network programming

What is Android UDP?

UDP is the abbreviation of user datagram protocol, and its Chinese name is user packet protocol. It is a connectionless transport layer protocol in OSI reference model, providing transaction oriented simple and unreliable information transmission service. It is the formal specification of IETF RFC 768 and UDP. In the network, it is used to process packets like TCP protocol. In the OSI model, in the fourth layer - transport layer, it is on the upper layer of IP protocol. UDP does not provide datagram grouping, assembly and sorting. In other words, after the message is sent, it is impossible to know whether it arrives safely and completely. UDP is used to support network applications that need to transfer data between computers. Many client / server mode network applications, including network video conference system, need to use UDP protocol. UDP protocol has been used for many years since it came out. Although its initial glory has been covered by some similar protocols, even today, UDP is still a very practical and feasible network transport layer protocol.

Like the well-known TCP (transmission control protocol) protocol, UDP protocol is directly at the top level of IP (Internet Protocol). According to OSI (Open Systems Interconnection) reference model, UDP and TCP belong to transport layer protocols.

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

The use of TCP and UDP in Android is exactly the same as in Java.

Server:

client:

Primary activity:

Note: add the following in the configuration file:

To obtain the appropriate permissions.

design sketch:

Server side information printed by logcat:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>