December 2nd, 2004, 07:38 PM
TCP or UDP?
I am currently still learning Python but I've gotten pretty good at it. I'm working on creating a moderation bot for Battle.net. I know that for it's servers the two most popular types of connections used are TCP and UDP. Does anyone know which one would be a better choice going by stability and speed?
December 2nd, 2004, 07:52 PM
Generally TCP is better for stability, but UDP is better for speed.
The reasoning is:
UDP sends data and forgets about it. If the data arrives, good. If it doesn't then it gets lost forever and you never know (as far as you're concerned it was sent OK) and the other side never knows (because it didn't arrive).
TCP sends data and keeps track of it. If the data arrives, some more is sent back to say it arrived. If it doesn't arrive and return the acknowledgement in a set time, it is sent again and tracked again until it does arrive. If it doesn't get an acknowledgement in a set time, you can give up knowing it probably hasn't got through.This extra tracking and checking data being sent back and forth takes some overhead, so it is slower, but means if the data gets there at all it will be right, and it will even work (more slowly) over unreliable links.
TCP is typically used in most places unless the lower overhead of UDP is especially needed - some multiplayer games use UDP because being fast is more important than losing some data occasionally - so it probably makes more sense to use TCP.
December 2nd, 2004, 07:56 PM
Ok, thanks for the help, I'll stick with TCP.
December 3rd, 2004, 03:05 AM
sfb's description is spot on.
I'd just like to add my 2 cents...
What will your moderation bot be required to do?
TCP, although very stable, seems like an overkill to me if it's just a bot we're talking about. It's true that speed isn't a factor here, therefore UDP's advantages aren't really beneficial, but for a meager bot? I think TCP's advantages aren't going to come much in handy either.
afaik, a bot just needs to carry out simple tasks that don't necessarily require ordering of packets. If a UDP packet arrives, it's garantueed to be error-free, regardless of order. You could easily write some extra code that takes care of acknowledgements (something like an ACK UDP packet for example).
Although I agree with sfb's reasoning, I personally feel TCP is an overkill for a bot, and since UDP is far more easier to implement (in my experience anyway) I'd stick to that.
Again, I must stress the importance of the bot's required functionality. It all depends on that.
Bless me for being difficult.