Tech Blog

UDP, TCP, which should you choose?

A lot of my posts recently have been about networking. I have been working a lot with a combination of UDP and TCP, so I thought I would highlight the key differences between the two.

UDP

TCP

TCP stands for Transmission Control Protocol. 

  • TCP is a connection-oriented protocol.
  • TCP is suited for applications that require high reliability, and transmission time is relatively less critical
  • The speed for TCP is slower than UDP because there are check sums on the data at the lower layers
  • TCP header size is 20 bytes
  • There is absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent
  • Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.
  • TCP is heavy-weight. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
  • No Acknowledgment

UDP stands for User Datagram Protocol

  • UDP is a connectionless protocol.
  • UDP is suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.
  • UDP is faster because error recovery is not attempted. It is a "best effort" protocol
  • UDP Header size is 8 bytes
  • 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.
  • UDP is lightweight. There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
  • Acknowledgement segments


Summary

TCP is useful for the guarantee of delivery of the data. TCP is slower than UDP, it is meant for real time data, often used for gaming, specifically any real time multi-player games, or handling any sort of information that doesn't necessarily need to be delivered. TCP would be great for server communications or data delivery, file transfers. 

This is sums it up nicely.

redditTCP.png
dan flan