UDP and TCP: Comparison of Transport Protocols


You have most likely heard of sockets, and are probably aware that there are two main types: TCP and UDP. When writing a network game, we first need to choose what type of socket to use. Do we use TCP sockets, UDP sockets or a mixture of both?


TCP ( Transmission Control Protocol )

  • Connection based 
  • Guaranteed reliable and ordered 
  • Automatically breaks up your data into packets for you
  •  Makes sure it doesn't send data too fast for the internet connection to handle (flow control)
  •  Easy to use, you just read and write data like its a file

UDP ( User Datagram Protocol )

  • No concept of connection, you have to code this yourself
  •  No guarantee of reliability or ordering of packets, they may arrive out of order, be duplicated, or not arrive at all! 
  • You have to manually break your data up into packets and send them 
  • You have to make sure you don’t send data too fast for your internet connection to handle
  •  If a packet is lost, you need to devise some way to detect this, and resend that data if necessary

Post a Comment

Thank you for vising

Previous Post Next Post