C # network programming personal understanding of UDP & TCP

Source: Internet
Author: User
Due to recent interests, I started to write about network programming. I want to write about network programming in C #. If anything is wrong, please correct me.

Basics:
This article focuses on understanding and theoretical knowledge. As a result, my documents are limited. Therefore, please correct the error.
Network Programming mainly uses two Protocols: TCP and UDP
TCP programming features:
For TCP, the most important thing to remember is that it is a link-oriented protocol. Once a connection exists between two devices, a reliable data stream is formed to ensure that the data is accurately transferred from one device to another. Although TCP users do not have to worry about data loss and dislocation. However, when using TCP programming, the major issue to be considered is the buffer zone.
Because TCP must ensure data integrity, before receiving a positive response message "received data" from a remote device, it stores all sent data in a local buffer. Similarly, when receiving data from the network, TCP must also have a local buffer for receiving data, to ensure that all data blocks are received in order before the data is delivered to the application. Because of this separate TCP buffer, it is more difficult to move data between the user program and the Target Program on the remote host than expected. Therefore, both the sender and receiver data are first placed in the buffer when they are sent or received. However, TCP does not retain the boundary of data messages (the boundary between data blocks), that is, data blocks in the buffer zone are sent as a package. So programmers must make up for it in their own network programs.

Features of UDP programming:
UDP is created to solve the message Boundary Problem of TCP. UDP retains the data boundary of all messages sent from an application to the network. Due to the special design of UDP, it does not have to worry about reliable data transmission. It does not need to use local buffers to retain the data sent or received. Instead, when a message is received from an application, each message is forwarded as a separate packet. Similarly, each message received from the network is forwarded to the application as a separate package. UDP retains the message boundary in the Network Package. However, because UDP does not guarantee data transmission, user applications must implement this function if it involves data arriving at the destination. Because a device sends a UDP packet, it does not necessarily mean that the device receives the packet. Therefore, the user must ensure that the user program can handle the packet loss problem.
When the program needs to distinguish between the server and the client, it is best to use the TCP protocol, and UDP is generally used when the primary and secondary are not very clear (that is, the relationship is equal.

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.