Comments (1)

UDP details

1、 In TCP / IP protocol stack, what are the connections and differences between TCP protocol and UDP protocol?

Contact:

TCP and UDP are two protocols of the transport layer in the TCP / IP protocol stack. They use the network layer function to send packets to the destination, so as to provide network services for the application layer.

Difference:

      1. TCP is a connection oriented transport. UDP is a connectionless transport.

      2. TCP guarantees that the data will arrive in the sending order, but UDP cannot.

      4. TCP is reliable transmission, while UDP is unreliable transmission.

      5. Because UDP lacks a lot of control information, the transmission speed is faster than TCP.

      6. TCP is suitable for transmitting a large amount of data, and UDP is suitable for transmitting a small amount of data.

For example, the communication between server and client is like. The communication between server and client is like.

II. Characteristics of UDP communication protocol:

      1. Encapsulate the data pole as a packet, facing connectionless.

       2. The size of each packet is limited to 64K

       3. Unreliable because there is no connection

      4. Because there is no need to establish a connection, it is fast

      5. UDP communication does not distinguish between server and client, but only distributes the sender and receiver.

Third, how to write UDP?

To send data:

        1. Create socket service

        2. Create package

        3. Encapsulate data into packets, add IP and ports, and data

        4. send out

        5. close resource

Steps for receiving data:

        1. Create a socket service and listen on the port

        2. Create a packet to receive data

        3. Receive data into data packet with socket

        4. Fetch data from packet

        5. close resource

Fourth, the code realizes UDP communication

    2. Server code

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
分享
二维码
< <上一篇
下一篇>>