Java Network Programming (2)--UDP and TCP

Source: Internet
Author: User

First, the two types of protocols are described first:

  UDP: UDP is the abbreviation of User Datagram protocol, the Chinese name is a Subscriber datagram protocol, is a connectionless transport layer protocol in the OSI (Open System interconnection, open Systems Interconnect) Reference Model, Provides a transaction-oriented simple unreliable information transfer service, the full name of the UDP protocol is the User Datagram Protocol [1], in the network it is the same as the TCP protocol for processing packets, 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. (Baidu Encyclopedia)

Features: No need to establish a connection, packet size limit in 64K, unreliable protocol, because no need to connect, so fast;

Common applications: Chat, web video

For example, e-mail in the life, email, regardless of the other side, sent past is;

  TCP: TCP (transmission Control Protocol Transmission Protocol) is a connection-oriented, reliable, byte-stream-based Transport layer communication protocol. In the simplified computer network OSI model, it accomplishes the function specified by layer Fourth transport layer, and the User Datagram Protocol (UDP) is another important transport protocol within the same layer [1]. In the Internet Protocol family (Internet Protocol suite), the TCP layer is the middle tier located above the IP layer and below the application layer. There is often a need for reliable, pipe-like connections between the application tiers of different hosts, but the IP layer does not provide such a flow mechanism, but rather provides unreliable packet switching.

Characteristics: Need to establish a connection to form a data channel;

A large number of transmissions can be made in the connection;

Through three handshake to complete the connection, is a reliable protocol;

Low efficiency compared to UDP;

Common applications: downloading, transferring files

For example, we live in the telephone, no two connected to the word is unable to communicate, at this time the equivalent of access to the channel, communication is equivalent to the transmission of data;

Why do you say this, which is the basic knowledge of network programming, and what in Java provides to enable us to communicate through these protocols?

That's the socket, and what we usually call Java's network programming is actually the socket programming:

Sockets are a mechanism for network services that can transmit data at both ends of the socket via IO!

So different protocols follow the same criteria, so for different protocols there are different socket implementation classes.

For example, the datagramsocket of UDP; TCP is the socket and serversocket, below I will describe in detail = =.

Java Network Programming (2)--UDP and TCP

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.