Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UdpClient vs TcpClient

Tags:

c#

.net

what is the difference between UdpClient and TcpClient ? When should i use Tcp and when Udp from the point of software arhitecture ? I hope i've explained it right ..

like image 796
Alex Avatar asked Apr 08 '11 11:04

Alex


2 Answers

TCP vs UDP comparison - Usage

  • TCP is used in case of non-time critical applications.
  • UDP is used for games or applications that require fast transmission of data. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.

TCP vs UDP comparison - Function

  • As a message makes its way across the internet from one computer to another. This is connection based.
  • UDP is also a protocol used in message transport or transfer. This is not connection based which means that one program can send a load of packets to another and that would be the end of the relationship.

TCP vs UDP comparison - Acronym for

  • Transmission Control Protocol
  • User Datagram Protocol or Universal Datagram Protocol

TCP vs UDP comparison - Weight

  • TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
  • UDP is lightweight. There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.

TCP vs UDP comparison - Streaming of data

  • Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.
  • Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.

TCP vs UDP comparison - Speed of transfer

  • The speed for TCP in comparison with UDP is slower.
  • UDP is faster because there is no error-checking for packets.

TCP vs UDP comparison - Examples

  • HTTP, HTTPs, FTP, SMTP Telnet etc...
  • DNS, DHCP, TFTP, SNMP, RIP, VOIP etc...

TCP vs UDP comparison - Data Reliability

  • There is absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent.
  • There is no guarantee that the messages or packets sent would reach at all.

TCP vs UDP comparison - Connection Reliable

  • Two way Connection reliable
  • one way Connection Reliable

TCP vs UDP comparison - Ordering

  • TCP rearranges data packets in the order specified.
  • UDP does not order packets. If ordering is required, it has to be managed by the application layer.

TCP vs UDP comparison - Error Checking

  • TCP does error checking
  • UDP does not have an option for error checking.

TCP vs UDP comparison - Header Size

  • TCP header size is 20 bytes
  • UDP Header size is 8 bytes.

Short compare. Must have book.

like image 57
Naszta Avatar answered Sep 19 '22 15:09

Naszta


Basically,

  • UDP is faster than TCP because packets are sent without guarantee of delivery nor order
  • TCP is safer, because each packet is acknowledged and ordered

You should have a read at those links :

  • UDP vs TCP, how much faster is it?
  • http://www.skullbox.net/tcpudp.php (short)
  • http://www.laynetworks.com/Comparative%20analysis_TCP%20Vs%20UDP.htm (long)
like image 34
mathieu Avatar answered Sep 23 '22 15:09

mathieu