When should I use UDP instead of TCP?



When should I use UDP instead of TCP?..

Answer / chaitanya

UDP is good for sending messages from one system to another when the order isn't important and you don't need all of the messages to get to the other machine. This is why I've only used UDP once to write the example code for the faq. Usually TCP is a better solution. It saves you having to write code to ensure that messages make it to the desired destination, or to ensure the message ordering. Keep in mind that every additional line of code you add to your project in another line that could contain a potentially expensive bug.

If you find that TCP is too slow for your needs you may be able to get better performance with UDP so long as you are willing to sacrifice message order and/or reliability.

UDP must be used to multicast messages to more than one other machine at the same time. With TCP an application would have to open separate connections to each of the destination machines and send the message once to each target machine. This limits your application to only communicate with machines that it already knows about.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Unix Socket Programming Interview Questions

What is Mac, and how is it different from PC? Which one is better for professional users, and why

1 Answers   Evolving Systems, IBM,


What does af mean in sockets?

0 Answers  


Why do not my sockets close?

1 Answers  


What is a sae socket?

0 Answers  


Can a single socket port be used for multiple applications?

0 Answers  






system choose one for me on the connect() call? Should I bind() a port number in my client program, or let the?

0 Answers  


What is the purpose of socket?

0 Answers  


How can I read ICMP errors from connected UDP sockets?

1 Answers  


What's better 6pt or 12pt sockets?

0 Answers  


How many sockets can a cpu have?

0 Answers  


Can multiple clients connect to same socket?

0 Answers  


If bind() fails, what should I do with the socket descriptor?

1 Answers  


Categories