Thread: TCP or UDP?

    #1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    a better choice going by stability and speed?
    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.
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Ok, thanks for the help, I'll stick with TCP.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Cape Town, South Africa
    Posts
    131
    Rep Power
    12
    Heya

    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.

    Cheers,
    K

IMN logo majestic logo threadwatch logo seochat tools logo