Hi everyone, My program is a cyber cafe program and Server will control clients(opening-closing account,sending files, taking screenshot, closing running applications etc.) and clients will be able to: order drinks,send message etc.

So, for best performance, Should I use TCP or UDP? Thanks in advance

+7  A: 

For a massive reduction in coding effort, pain, debugging, user-complaints and more, use TCP.

Marcelo Cantos
+3  A: 

I'd rather go for reliability instead and use TCP. Besides, for transferring files (the screenshots you mentioned) UDP is not so suitable since the packets can reach you out-of-order and you'll have to reorder them => you'll need some packet numbering on top of UDP, etc. etc. (TL;DR use TCP).


UDP will for sure give you the best performance because it is connection-less (you save the expensive connect call from TCP and the TCP flag management during transmissions). However develop some safe acknowledgement in your communication because the transmission is not guaranteed. However in a local network it should rarely be a problem, excepting if your customers pull or twist the cables :-). If your protocol becomes more complicated and want more than command/response pairs before reinventing the wheel rather consider taking TCP.

+2  A: 

Given that you're likely to only have a couple dozen client computers connected to the server, and they're all going to be running on a LAN, then performance is not your biggest concern.

Given that, TCP is definitely the way to go. You don't want the headaches of out-of-order packets, dropped packets and duplicated packets that can happen with UDP (though over a LAN, a lot of those problems are minimised - though not eliminated).

Dean Harding

IMHO the main difference between TCP and UDP is, TCP makes sure that packages arrives the destination and UDP does not. Because of that UDP is a bit faster than TCP.

As I understand your program I would use TCP, because your task, seems like they have to work and the network connection have to be reliable. I would use UDP only for tasks, where some packages can be lost, e.g. broadcasting the temperature from a sensor.


The U in UDP is often believed to stand for Unreliable (*). If you use UDP, then any time (and there will be some!) you need reliability in your server's networking you will need to program your own higher level protocols to detect packet loss, perform retry and so on. This is not simple, and it is particularly hard to do in a "user space" application. TCP deals with packet loss detection, out of order packet detection, retries, and so on ... without you having to worry about it at the application level.

Another issue is that a lot of firewalls, routers, gateways etc will block all UDP traffic by default.

IMO, you should only consider using UDP in situations where:

  • loss of data is acceptable, and
  • maximum network performance is an absolute, overriding requirement.

[* - Actually, UDP stands for User Datagram Protocol.]

Stephen C
+1  A: 

I can't think of any reason whatsoever why you should choose UDP in this situation.