9 Departure Betwixt Tcp Together With Udp Protocol - Coffee Network Interview Question

Advertisement

Masukkan script iklan 970x90px

9 Departure Betwixt Tcp Together With Udp Protocol - Coffee Network Interview Question

Rabu, 24 Februari 2021

TCP too UDP are 2 carry layer protocols, which are extensively used on the cyberspace for transmitting information from ane host to another. Good noesis of how TCP too UDP works is essential for whatsoever programmer. That's why the difference betwixt TCP too UDP is ane of the most pop programming interview questions. I have got seen this query many times on diverse Java interviews, specially for server-side Java developer positions. Since FIX (Financial Information Exchange) protocol is likewise a TCP based protocol, several investment banks, hedge funds, too telephone substitution solution provider looks for Java developer amongst expert noesis of TCP too UDP. Writing ready engines too server side components for high-speed electronic trading platforms needs capable developers amongst a enterprise agreement of fundamentals including information structure, algorithms, too networking.

By the way, purpose of TCP too UDP is non express to ane area, it's at the pump of the internet. The protocol which is the substance of internet, HTTP is based on TCP. One to a greater extent than reason, why Java developer should empathise these 2 protocols inwards particular is that Java is extensively used to write multi-threaded, concurrent too scalable servers.

Java likewise provides rich Socket programming API for both TCP too UDP based communication. In this article, nosotros volition larn key differences betwixt TCP too UDP protocol, which is useful to every Java programmers.

To starting fourth dimension with, TCP stands for Transmission Control Protocol too UDP stands for User Datagram Protocol, too both are used extensively to create Internet applications.




Difference betwixt TCP vs UDP Protocol

I dear to compare 2 things at unlike points, this non entirely makes them piece of cake to compare exactly likewise makes it piece of cake to recall differences. When nosotros compare TCP to UDP, nosotros larn the divergence inwards how both TCP too UDP works, nosotros larn which provides reliable too guaranteed delivery too which doesn't. Which protocol is fast too why, too most importantly when to lead TCP over UDP field edifice your ain distributed application.

In this article, nosotros volition run into the difference betwixt UDP too TCP inwards ix points, e.g. connexion set-up, reliability, ordering, speed, overhead, header size, congestion control, application, unlike protocols based on TCP too UDP too how they transfer data.

By learning these differences, you lot non entirely able to answer this interview query improve exactly likewise empathise approximately of import details virtually 2 of the most of import protocols of the internet.



1) Connection-oriented vs Connectionless
First too initiative divergence betwixt them is TCP is a connection-oriented protocol, too UDP is connectionless protocol. This agency a connexion is established betwixt customer too server earlier they tin post data. Connection institution procedure is likewise known equally TCP handshaking where command messages are interchanged betwixt customer too server. Attached icon depict the procedure of TCP handshake, for example, which command messages are exchanged betwixt customer too server.

The client, which is the initiator of TCP connection, sends SYN message to the server, which is listening on a TCP port. The server receives too sends an SYN-ACK message, which is received yesteryear customer ane time again too responded using ACK. Once the server receives this ACK message,  TCP connexion is established too ready for information transmission.

On the other hand, UDP is a connectionless protocol, too signal to signal connexion is non established earlier sending messages. That's the reason, UDP is to a greater extent than suitable for multicast distribution of the message, ane to many distributions of information inwards unmarried transmission.


 TCP too UDP are 2 carry layer protocols ix Difference betwixt TCP too UDP Protocol - Java Network Interview Question


2) Reliability
TCP provides the delivery guarantee, which agency a message sent using TCP protocol is guaranteed to live on delivered to the client. If a message is lost inwards transits hence its recovered using resending, which is handled yesteryear TCP protocol itself. On the other hand, UDP is unreliable, it doesn't furnish whatsoever delivery guarantee. H5N1 datagram packet may live on lost inwards transits. That's why UDP is non suitable for programs which require guaranteed delivery.


3) Ordering
Apart from the delivery guarantee, TCP likewise guarantees the guild of message. The message volition live on delivered to the customer inwards the same order, the server has sent, though it's possible they may achieve out of guild to the other destination of the network. TCP protocol volition do all sequencing too ordering for you. UDP doesn't furnish whatsoever ordering or sequencing guarantee.

Datagram packets may brand it inwards whatsoever order. That's why TCP is suitable for application which needs delivery inwards a sequenced manner, though at that topographic point is UDP based protocol equally good which provides ordering too reliability yesteryear using sequence number too redelivery e.g. TIBCO Rendezvous, which is truly a UDP based application.



4) Data Boundary
TCP does non save information boundary, UDP does. In Transmission command protocol, information is sent equally a byte stream, too no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually too are checked for integrity entirely if they arrived. Packets have got definite boundaries which are honored upon receipt, pregnant a read performance at the receiver socket volition yield an entire message equally it was originally sent. Though TCP volition likewise deliver the consummate message later on assembling all bytes. Messages are stored on TCP buffers earlier sending to brand optimum purpose of network bandwidth.


5) Speed
In ane word, TCP is boring too UDP is fast. Since TCP does has to create a connection, ensure guaranteed too ordered delivery, it does a lot to a greater extent than than UDP. This terms TCP inwards terms of speed, that's why UDP is to a greater extent than suitable where speed is a concern, for example, online video streaming, telecast or online multiplayer games. If you lot desire to larn to a greater extent than virtually why UDP is faster than TCP hence consider reading The TCP/IP Guide,  A Comprehensive, Illustrated Internet Protocols Reference 1st Edition
yesteryear Charles M. Kozierok, ane of the must-read books to larn TCP/IP protocol.

 TCP too UDP are 2 carry layer protocols ix Difference betwixt TCP too UDP Protocol - Java Network Interview Question



6) Heavyweight vs Lightweight
Because of the overhead mentioned above, Transmission command protocol is considered equally heavyweight equally compared to lightweight UDP protocol. Simple mantra of UDP to deliver a message without bearing whatsoever overhead of creating connexion too guaranteeing delivery or guild guarantee keeps it lite weight. This is likewise reflected inwards their header sizes, which is used to carry metadata.


7) Header size
TCP has bigger header than UDP. Usual header size of a TCP packet is twenty bytes which are to a greater extent than than double of 8 bytes, header size of UDP datagram packet. TCP header contains Sequence Number, Ack number, Data offset, Reserved, Control bit, Window, Urgent Pointer, Options, Padding, Check Sum, Source port, too Destination port. While UDP header entirely contains Length, Source port, Destination port, too Check Sum. Here is how TCP too UDP header looks like:

TCP Header Format


UDP Header Format 



8) Congestion or Flow control
TCP does Flow Control. TCP requires iii packets to fix a socket connexion earlier whatsoever user information tin live on sent. TCP handles reliability too congestion control. On the other hand, UDP does non have got an alternative for period of time control. See TCP/IP Illustrated - The Protocol Volume 1  By W. Richard Stevens to larn to a greater extent than virtually how TCP does period of time control

 TCP too UDP are 2 carry layer protocols ix Difference betwixt TCP too UDP Protocol - Java Network Interview Question



9) Usage too application
Where do TCP too UDP are used on the internet? After knowing key differences betwixt TCP too UDP, nosotros tin easily conclude, which province of affairs suits them. Since TCP provides delivery too sequencing guaranty, it is best suited for applications that require high reliability, too transmission fourth dimension is relatively less critical.

While UDP is to a greater extent than suitable for applications that bespeak fast, efficient transmission, such equally games. UDP's stateless nature is likewise useful for servers that answer pocket-size queries from huge numbers of clients. In practice, TCP is used inwards finance domain e.g. FIX protocol is a TCP based protocol, UDP is used heavily inwards gaming too amusement sites.




10) TCP too UDP based Protocols
One of the best examples of TCP based higher destination protocol is HTTP too HTTPS, which is everywhere on the internet. In fact, most of the mutual protocol you lot are familiar of e.g. Telnet, FTP too SMTP all are based on Transmission Control Protocol. UDP don't have got anything equally pop equally HTTP exactly UDP is used inwards a protocol similar DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System). Some of the other protocol, which is based on User Datagram protocol is Simple Network Management Protocol (SNMP), TFTP, BOOTP and NFS (early versions).

Btw, field working inwards TCP/UDP based application on Linux, it's likewise expert to remember basic networking commands e.g. telnet and netstat, they attention tremendously to debug or troubleshoot whatsoever connexion issue.


That's all virtually the difference betwixt TCP too UDP protocol. Always recall to get upward that TCP is connexion oriented, reliable, slow, provides guaranteed delivery too preserves the guild of messages, field UDP is connectionless, unreliable, no ordering guarantee, exactly a fast protocol. TCP overhead is likewise much higher than UDP, equally it transmits to a greater extent than metadata per packet than UDP.

It's worth mentioning that header size of Transmission command protocol is twenty bytes, compared to 8 bytes header of User Datagram protocol. Use TCP, if you lot can't afford to lose whatsoever message, field UDP is improve for high-speed information transmission, where loss of a unmarried packet is acceptable e.g. video streaming or online multiplayer games.

Further Reading
The Complete Java MasterClass
Java Network Programming, (4th Addition) yesteryear Harold, Elliotte Rusty
TCP/IP too Networking Fundamentals for information technology Pros