9 Divergence Betwixt Tcp Together With Udp Protocol - Coffee Network Interview Question
TCP as well as UDP are ii carry layer protocols, which are extensively used on the cyberspace for transmitting information from 1 host to another. Good noesis of how TCP as well as UDP works is essential for whatever programmer. That's why the difference betwixt TCP as well as UDP is 1 of the most pop programming interview questions. I have got seen this query many times on diverse Java interviews, peculiarly for server-side Java developer positions. Since FIX (Financial Information Exchange) protocol is too a TCP based protocol, several investment banks, hedge funds, as well as telephone commutation solution provider looks for Java developer amongst skillful noesis of TCP as well as UDP. Writing create engines as well as server side components for high-speed electronic trading platforms needs capable developers amongst a enterprise agreement of fundamentals including information structure, algorithms, as well as networking.
By the way, role of TCP as well as UDP is non express to 1 area, it's at the pump of the internet. The protocol which is the heart as well as soul of internet, HTTP is based on TCP. One to a greater extent than reason, why Java developer should empathise these ii protocols inwards particular is that Java is extensively used to write multi-threaded, concurrent as well as scalable servers.
Java too provides rich Socket programming API for both TCP as well as UDP based communication. In this article, nosotros volition larn key differences betwixt TCP as well as UDP protocol, which is useful to every Java programmers.
To kickoff with, TCP stands for Transmission Control Protocol as well as UDP stands for User Datagram Protocol, as well as both are used extensively to create Internet applications.
In this article, nosotros volition run into the difference betwixt UDP as well as TCP inwards nine points, e.g. connectedness set-up, reliability, ordering, speed, overhead, header size, congestion control, application, unlike protocols based on TCP as well as UDP as well as how they transfer data.
By learning these differences, you lot non entirely able to answer this interview query meliorate merely too empathise or thus of import details near ii of the most of import protocols of the internet.
1) Connection-oriented vs Connectionless
First as well as initiative of all divergence betwixt them is TCP is a connection-oriented protocol, as well as UDP is connectionless protocol. This way a connectedness is established betwixt customer as well as server earlier they tin give the axe mail data. Connection institution procedure is too known every bit TCP handshaking where command messages are interchanged betwixt customer as well as server. Attached icon clit the procedure of TCP handshake, for example, which command messages are exchanged betwixt customer as well as 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 as well as sends an SYN-ACK message, which is received yesteryear customer 1 time to a greater extent than as well as responded using ACK. Once the server receives this ACK message, TCP connectedness is established as well as ready for information transmission.
On the other hand, UDP is a connectionless protocol, as well as quest to quest connectedness is non established earlier sending messages. That's the reason, UDP is to a greater extent than suitable for multicast distribution of the message, 1 to many distributions of information inwards unmarried transmission.
2) Reliability
TCP provides the delivery guarantee, which way a message sent using TCP protocol is guaranteed to last delivered to the client. If a message is lost inwards transits as well as thus its recovered using resending, which is handled yesteryear TCP protocol itself. On the other hand, UDP is unreliable, it doesn't supply whatever delivery guarantee. Influenza A virus subtype H5N1 datagram packet may last lost inwards transits. That's why UDP is non suitable for programs which require guaranteed delivery.
3) Ordering
Apart from the delivery guarantee, TCP too guarantees the gild of message. The message volition last delivered to the customer inwards the same order, the server has sent, though it's possible they may achieve out of gild to the other terminate of the network. TCP protocol volition do all sequencing as well as ordering for you. UDP doesn't supply whatever ordering or sequencing guarantee.
Datagram packets may become far inwards whatever order. That's why TCP is suitable for application which needs delivery inwards a sequenced manner, though at that spot is UDP based protocol every bit good which provides ordering as well as reliability yesteryear using sequence number as well as 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 every bit a byte stream, as well as no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually as well as are checked for integrity entirely if they arrived. Packets have got definite boundaries which are honored upon receipt, important a read performance at the receiver socket volition yield an entire message every bit it was originally sent. Though TCP volition too deliver the consummate message subsequently assembling all bytes. Messages are stored on TCP buffers earlier sending to brand optimum role of network bandwidth.
5) Speed
In 1 word, TCP is wearisome as well as UDP is fast. Since TCP does has to create a connection, ensure guaranteed as well as ordered delivery, it does a lot to a greater extent than than UDP. This toll TCP inwards damage 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 near why UDP is faster than TCP as well as thus consider reading The TCP/IP Guide, A Comprehensive, Illustrated Internet Protocols Reference 1st Edition
yesteryear Charles M. Kozierok, 1 of the must-read books to larn TCP/IP protocol.
6) Heavyweight vs Lightweight
Because of the overhead mentioned above, Transmission command protocol is considered every bit heavyweight every bit compared to lightweight UDP protocol. Simple mantra of UDP to deliver a message without bearing whatever overhead of creating connectedness as well as guaranteeing delivery or gild guarantee keeps it lite weight. This is too 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, as well as Destination port. While UDP header entirely contains Length, Source port, Destination port, as well as Check Sum. Here is how TCP as well as UDP header looks like:
8) Congestion or Flow control
TCP does Flow Control. TCP requires iii packets to prepare a socket connectedness earlier whatever user information tin give the axe last sent. TCP handles reliability as well as congestion control. On the other hand, UDP does non have got an alternative for catamenia control. See TCP/IP Illustrated - The Protocol Volume 1 By W. Richard Stevens to larn to a greater extent than near how TCP does catamenia control
9) Usage as well as application
Where do TCP as well as UDP are used on the internet? After knowing key differences betwixt TCP as well as UDP, nosotros tin give the axe easily conclude, which province of affairs suits them. Since TCP provides delivery as well as sequencing guaranty, it is best suited for applications that require high reliability, as well as transmission fourth dimension is relatively less critical.
While UDP is to a greater extent than suitable for applications that hollo for fast, efficient transmission, such every bit games. UDP's stateless nature is too useful for servers that answer minor 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 as well as amusement sites.
10) TCP as well as UDP based Protocols
One of the best examples of TCP based higher terminate protocol is HTTP as well as HTTPS, which is everywhere on the internet. In fact, most of the mutual protocol you lot are familiar of e.g. Telnet, FTP as well as SMTP all are based on Transmission Control Protocol. UDP don't have got anything every bit pop every bit HTTP merely 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, piece working inwards TCP/UDP based application on Linux, it's too skillful to remember basic networking commands e.g. telnet and netstat, they assistance tremendously to debug or troubleshoot whatever connectedness issue.
That's all near the difference betwixt TCP as well as UDP protocol. Always hollo back to elevate that TCP is connectedness oriented, reliable, slow, provides guaranteed delivery as well as preserves the gild of messages, piece UDP is connectionless, unreliable, no ordering guarantee, merely a fast protocol. TCP overhead is too much higher than UDP, every bit 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 whatever message, piece UDP is meliorate 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 as well as Networking Fundamentals for information technology Pros
By the way, role of TCP as well as UDP is non express to 1 area, it's at the pump of the internet. The protocol which is the heart as well as soul of internet, HTTP is based on TCP. One to a greater extent than reason, why Java developer should empathise these ii protocols inwards particular is that Java is extensively used to write multi-threaded, concurrent as well as scalable servers.
Java too provides rich Socket programming API for both TCP as well as UDP based communication. In this article, nosotros volition larn key differences betwixt TCP as well as UDP protocol, which is useful to every Java programmers.
To kickoff with, TCP stands for Transmission Control Protocol as well as UDP stands for User Datagram Protocol, as well as both are used extensively to create Internet applications.
Difference betwixt TCP vs UDP Protocol
I honey to compare ii things at unlike points, this non entirely makes them piece of cake to compare merely too makes it piece of cake to hollo back differences. When nosotros compare TCP to UDP, nosotros larn the divergence inwards how both TCP as well as UDP works, nosotros larn which provides reliable as well as guaranteed delivery as well as which doesn't. Which protocol is fast as well as why, as well as most importantly when to guide TCP over UDP piece edifice your ain distributed application.In this article, nosotros volition run into the difference betwixt UDP as well as TCP inwards nine points, e.g. connectedness set-up, reliability, ordering, speed, overhead, header size, congestion control, application, unlike protocols based on TCP as well as UDP as well as how they transfer data.
By learning these differences, you lot non entirely able to answer this interview query meliorate merely too empathise or thus of import details near ii of the most of import protocols of the internet.
1) Connection-oriented vs Connectionless
First as well as initiative of all divergence betwixt them is TCP is a connection-oriented protocol, as well as UDP is connectionless protocol. This way a connectedness is established betwixt customer as well as server earlier they tin give the axe mail data. Connection institution procedure is too known every bit TCP handshaking where command messages are interchanged betwixt customer as well as server. Attached icon clit the procedure of TCP handshake, for example, which command messages are exchanged betwixt customer as well as 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 as well as sends an SYN-ACK message, which is received yesteryear customer 1 time to a greater extent than as well as responded using ACK. Once the server receives this ACK message, TCP connectedness is established as well as ready for information transmission.
On the other hand, UDP is a connectionless protocol, as well as quest to quest connectedness is non established earlier sending messages. That's the reason, UDP is to a greater extent than suitable for multicast distribution of the message, 1 to many distributions of information inwards unmarried transmission.
2) Reliability
TCP provides the delivery guarantee, which way a message sent using TCP protocol is guaranteed to last delivered to the client. If a message is lost inwards transits as well as thus its recovered using resending, which is handled yesteryear TCP protocol itself. On the other hand, UDP is unreliable, it doesn't supply whatever delivery guarantee. Influenza A virus subtype H5N1 datagram packet may last lost inwards transits. That's why UDP is non suitable for programs which require guaranteed delivery.
3) Ordering
Apart from the delivery guarantee, TCP too guarantees the gild of message. The message volition last delivered to the customer inwards the same order, the server has sent, though it's possible they may achieve out of gild to the other terminate of the network. TCP protocol volition do all sequencing as well as ordering for you. UDP doesn't supply whatever ordering or sequencing guarantee.
Datagram packets may become far inwards whatever order. That's why TCP is suitable for application which needs delivery inwards a sequenced manner, though at that spot is UDP based protocol every bit good which provides ordering as well as reliability yesteryear using sequence number as well as 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 every bit a byte stream, as well as no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually as well as are checked for integrity entirely if they arrived. Packets have got definite boundaries which are honored upon receipt, important a read performance at the receiver socket volition yield an entire message every bit it was originally sent. Though TCP volition too deliver the consummate message subsequently assembling all bytes. Messages are stored on TCP buffers earlier sending to brand optimum role of network bandwidth.
5) Speed
In 1 word, TCP is wearisome as well as UDP is fast. Since TCP does has to create a connection, ensure guaranteed as well as ordered delivery, it does a lot to a greater extent than than UDP. This toll TCP inwards damage 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 near why UDP is faster than TCP as well as thus consider reading The TCP/IP Guide, A Comprehensive, Illustrated Internet Protocols Reference 1st Edition
yesteryear Charles M. Kozierok, 1 of the must-read books to larn TCP/IP protocol.
6) Heavyweight vs Lightweight
Because of the overhead mentioned above, Transmission command protocol is considered every bit heavyweight every bit compared to lightweight UDP protocol. Simple mantra of UDP to deliver a message without bearing whatever overhead of creating connectedness as well as guaranteeing delivery or gild guarantee keeps it lite weight. This is too 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, as well as Destination port. While UDP header entirely contains Length, Source port, Destination port, as well as Check Sum. Here is how TCP as well as UDP header looks like:
TCP Header Format
UDP Header Format
8) Congestion or Flow control
TCP does Flow Control. TCP requires iii packets to prepare a socket connectedness earlier whatever user information tin give the axe last sent. TCP handles reliability as well as congestion control. On the other hand, UDP does non have got an alternative for catamenia control. See TCP/IP Illustrated - The Protocol Volume 1 By W. Richard Stevens to larn to a greater extent than near how TCP does catamenia control
9) Usage as well as application
Where do TCP as well as UDP are used on the internet? After knowing key differences betwixt TCP as well as UDP, nosotros tin give the axe easily conclude, which province of affairs suits them. Since TCP provides delivery as well as sequencing guaranty, it is best suited for applications that require high reliability, as well as transmission fourth dimension is relatively less critical.
While UDP is to a greater extent than suitable for applications that hollo for fast, efficient transmission, such every bit games. UDP's stateless nature is too useful for servers that answer minor 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 as well as amusement sites.
10) TCP as well as UDP based Protocols
One of the best examples of TCP based higher terminate protocol is HTTP as well as HTTPS, which is everywhere on the internet. In fact, most of the mutual protocol you lot are familiar of e.g. Telnet, FTP as well as SMTP all are based on Transmission Control Protocol. UDP don't have got anything every bit pop every bit HTTP merely 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, piece working inwards TCP/UDP based application on Linux, it's too skillful to remember basic networking commands e.g. telnet and netstat, they assistance tremendously to debug or troubleshoot whatever connectedness issue.
That's all near the difference betwixt TCP as well as UDP protocol. Always hollo back to elevate that TCP is connectedness oriented, reliable, slow, provides guaranteed delivery as well as preserves the gild of messages, piece UDP is connectionless, unreliable, no ordering guarantee, merely a fast protocol. TCP overhead is too much higher than UDP, every bit 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 whatever message, piece UDP is meliorate 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 as well as Networking Fundamentals for information technology Pros





Komentar
Posting Komentar