9 Differences between TCP and UDP Protocol-java Network interview question-translation

Source: Internet
Author: User
Tags ack

Original: http://www.javacodegeeks.com/2014/07/9- Differences-between-tcp-and-udp-protocol-java-network-interview-question.html?utm_source=tuicool

tcp and UDP two transport layer protocols, which are widely used in the Internet to send data between one host to another. A good understanding of how TCP and UDP works is essential for any programmer. That's why the difference between TCP and UDP is a popular Java programming interview problem. I've seen this problem many times in different Java interviews, especially for server-side Java developers. Because the fix (Financial Information Exchange) protocol is also a TCP-based protocol, several investment banks, hedge funds, and FX solution providers are looking for Java developers to have a good understanding of TCP and UDP knowledge. Write the fix engine and server-side components of the high-speed electronic trading platform that requires developers to have a deep understanding of fundamentals, including data structures, algorithms, and networks.



tcp and UDP protocol

> I like to compare two things differently, which not only makes them easy to compare, but also makes it easy to remember the differences. When we compare TCP with UDP, we learn how to compare between TCP and UDP, and we learn which one provides reliable and guaranteed delivery without distinction. This protocol is fast, so, most importantly, choose TCP over UDP while building your own distributed application. In this article, we'll look at 9 points, such as the difference between UDP and TCP connection establishment, reliability, sequencing, speed, overhead, header size, congestion control, application, TCP and UDP based, and how they transmit data with different protocols.

Connection-oriented vs. no connection

The first and most important difference between them is that TCP is a connection-oriented protocol, and UDP is a non-connected protocol. This means that the connection between the client and the server is established before data can be transmitted over TCP. The connection establishment process is also known as the TCP handshake, where the control message is exchanged between the client and the server. The image here describes the TCP handshake, the process of exchanging between the client and the server that controls the message. The client, which is the initiator of the TCP connection, sends a SYN message to the server, which is listening on a TCP port. The server receives and sends a SYN-ACK message, which is the receiving client again using an ACK response. Once the server receives the ACK message, the TCP connection is established and ready for data transfer. On the other hand, UDP is a no-connection protocol, and the point-to-point connection is not established until the message is sent. This is why UDP is more suitable for multicast information, one for a single transmission of data with many distribution multicast distributions.

Reliability

TCP provides delivery guarantees, which means that messages sent using the TCP protocol are guaranteed to be delivered to the customer. If the message is lost in transit, then it is used for re-sending, which is processed by the TCP protocol itself for recycling. On the other hand, UDP is unreliable and it does not provide any guarantee of delivery. Datagram packets may be lost during shipping. This is why UDP is not suitable for a guaranteed delivery scenario.

Sequential nature

In addition to the delivery guarantee, TCP also guarantees the order message. The message will be delivered to the client in the same order that the server sends them, although it may be possible to reach the other end of the network, not sequentially. The TCP protocol will do everything in the sort and order for you to serve. UDP does not provide guarantees of any order or sequence. Datagrams can be reached in any order. This is why TCP is suitable for applications, it needs to be delivered in a sorted manner, but there are also UDP-based protocols as well as its use of serial numbers and also ships, such as providing ordering and reliability Tibco Rendezvous, which is actually a UDP-based application.

Data boundaries

TCP does not preserve data boundaries, UDP. In the Transmission Control protocol, the data is sent by the byte stream and transmits no significant indication of the signal message (segment) of the boundary. The UDP messages will be sent separately and the integrity checked only when they arrive. What are the packages?? is in receipt of the honor, which means that the read operation on the receiving end socket will produce a complete message because it initially emits a definite boundary. Although TCP will also assemble all the bytes after providing the complete information. Messages are stored in the TCP send buffer to maximize network bandwidth before they are used.

Speed

In short, TCP is slow and UDP is fast. Because TCP does have to create a connection that guarantees guaranteed, ordered delivery, but it does much more than a lot of UDP. The cost of TCP in terms of speed, which is why UDP is more suitable for speed is an issue, such as online video streaming, TV shows or online multiplayer games.

Heavyweight and lightweight

Because of the overhead mentioned above, the Transmission Control protocol is considered heavy weight compared to light weight UDP. The simple UDP is to provide information that does not bear to establish a connection and to guarantee delivery or to guarantee any overhead. This is also reflected in the size of its header, which is used for bearer metadata.

The size of the header

TCP has a larger head than UDP. The header size of the TCP packet is typically 20 bytes, which is twice times more than 8 bytes, and the UDP datagram is grouped by the header sizes. The TCP header contains the serial number, confirmation number, data offset, hold, control bit, window, emergency pointer, select, fill, checksum, source port and destination port. The UDP header contains only the length, source port, destination port, checksum. Here's what the TCP and UDP headers look like:

Congestion and flow control

TCP does traffic control. TCP requires three guarantees to establish a socket connection before any user can send the data. TCP processing reliability and congestion control. On the other hand, UDP does not have options for flow control.

Use and application

TCP and UDP that will be used to surf the internet? Knowing the key differences between TCP and UDP, we can easily conclude that this is the case for them. Because TCP provides delivery and sequencing guarantees, and is best suited for applications that require high reliability, the transfer time is relatively less important. While UDP is more suitable for applications, it requires fast, efficient transmission, such as games. The stateless nature of UDP is also useful for servers to answer a large number of small queries from customers. In practice, the use of TCP in the financial sector such as the fix protocol is TCP-based protocol, while UDP is heavily used in gaming and entertainment sites.

based on TCP and UDP protocol

One of the best examples of TCP-based high-end protocols is HTTP and HTTPS, which are ubiquitous network connections. In fact, most commonly used protocols that you are familiar with, such as TELNET,FTP and SMTP, are based on the Transmission Control protocol. UDP is not much of a popular HTTP, but it is also widely used by protocols such as DHCP and DNS. Some of the other protocols that are based on the User Datagram Protocol are Simple Network Management Protocol (SNMP), TFTP,BOOTP and NFS (earlier versions).

It is important to remember that TCP is connection-oriented, reliable, slow, and provides guaranteed warranty and order information, while UDP is non-connected, unreliable, with no order of guarantee, but a fast protocol. The TCP overhead is also much higher than UDP because it transmits multiple metadata for each packet instead of UDP. It is worth mentioning that the Transmission Control protocol header has a size of 20 bytes, relative to the User Datagram Protocol 8 byte header. With TCP, if you can't afford to lose any of the messages, and UDP is a transmission for high-speed data, where the loss of a single packet is acceptable, such as better video streaming or online multiplayer games. While working on Linux based TCP/UDP applications, it is also good to remember basic network commands such as Telnet and netstat, which greatly help debug or resolve any connection issues.

9 Differences between TCP and UDP Protocol-java Network interview question-translation

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.