UDP vs TCP (networking)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Codex
Party member
Posts: 106
Joined: Tue Mar 06, 2012 6:49 am

UDP vs TCP (networking)

Post by Codex »

Alright so I just got done bugging the people on IRC, and they gave me some very useful info that I felt I should share with other beginners who ever get interested in creating an online multiplayer game.
[07:31] <Codex> does anyone know how to use UDP really well?
[07:32] <EntranceJew> Not a single person on earth.
[07:32] <TechnoCat> haha
[07:33] <TechnoCat> what does it even mean to use UDP really well
[07:34] <Codex> It's like asking a person do you play a sport really well?
[07:34] <Codex> if they are confident they do, then yes, and if they aren't, then no.
[07:34] <TechnoCat> UDP is a very minimal protocol
[07:35] <Codex> I'm looking to use it for a master server connecting to other servers if that's possible
[07:36] <EntranceJew> the problem is that knowledge is a spectrum between what and I am the documentation
[07:37] <McGooch> Most things are possible with UDP, but its most typical use is to build a higher level protocol.
[07:37] <McGooch> If you find a higher one that does what you want, that may save you some time
[07:37] <Codex> Well, I've seen different games able to connect all servers to a master server and I have no clue how to even go about finding out how they accomplished it.
[07:38] <McGooch> Well even the concept of a "connection" is higher than UDP
[07:38] <McGooch> it doesn't have connections
[07:38] <McGooch> TCP does
[07:38] <McGooch> Sounds more like you want a TCP socket
[07:39] <McGooch> At least to start until you have a clear idea why it won't work for you and why you need a custom protocol
[07:41] <Codex> so is TCP an advanced version of UDP?
[07:41] <Codex> (in rough terms?)
[07:41] <McGooch> I wouldn't quite say that exactly.
[07:42] <McGooch> UDP is very simple, but you can do very advanced/complex things with it that are impossible with TCP
[07:42] <slime> TCP is a very high level implementation on top of UDP
[07:42] <slime> relatively
[07:42] <slime> but TCP wasn't made with real-time games in mind
[07:43] <slime> so it has a lot of disadvantages in that regard
[07:43] <McGooch> Its more like driving standard vs automatic except more so. Like drive automatic vs build your own transmission
[07:43] <Codex> McGooch: Here is a rough idea of what I'm looking to do. Multiple servers, a master server, and database of passwords and usernames.
[07:43] <McGooch> TCP
[07:43] <Codex> Which one should I start looking at?
[07:43] <Codex> Ok then when you said that UDP let's you do things that TCP doesn't, what are some examples?
[07:44] <McGooch> Until you want more realtime constraints TCP will be fine
[07:44] <slime> ^
[07:44] <Codex> realtime? As in like a FPS?
[07:45] <McGooch> Stuff like that would need some UDP features.
[07:45] <TechnoCat> TCP relies on ACK's, UDP doesn't necessarily. =P
[07:45] <TechnoCat> it also has congestion control
[07:46] <McGooch> TCP is guaranteed to deliver its packets in the order they were sent, so if one gets lost, the TCP layer at the receiver halts delivering to the next layer up, asks for a resend, and things get backed up.
[07:46] <Codex> Thanks for the crash course in networking! :D
[07:47] <Codex> I did skim through the UDP wiki guide for love
[07:47] <McGooch> But in realtime tasks old data is often garbage anyway. So you generally need a different strategy than halt and resend
[07:47] <Codex> but I saw there was not one for TCP.
[07:47] <TechnoCat> because tcp is pretty dead simple to use
[07:48] <TechnoCat> it handles almost everything
[07:48] <TechnoCat> just slowly at times
[07:48] <McGooch> Its more like the automatic cadillac
[07:48] <Codex> lol, compared to a maunual?
[07:48] <Codex> :P
[07:48] <McGooch> No, compared to build your own transmission
[07:50] <McGooch> UDP is more like sending shakespeare via carrier pidgeon.
[07:50] <slime> lol
[07:51] <TechnoCat> i see some seriously hinting to start with TCP
[07:51] <McGooch> You cut up a small piece (cause they can't carry a lot), then you tell it where do go and throw it out the window.
[07:52] <McGooch> No guarantees that they get there via the same route, in what order, or get there at all, or even how to put the book back together.
[07:52] <Codex> xD
[07:53] <McGooch> You can think of TCP as a complex protocol that sits one layer up. Its extra rules that the sender and receiver use to sort things out.
[07:54] <TechnoCat> "one" layer up?
[07:54] <McGooch> Like how to number the messages, how to send back an acknowledgement that pigeon 3246 has arrived and to stop sending that message
[07:54] <TechnoCat> it sends pigeons back for each pigeon it gets
[07:55] <McGooch> Layers are the "actors" involved
[07:55] <TechnoCat> and each pigeon it gets back sucessfully it doubles the number of pigeons it sends at once
[07:56] <Codex> Q: Is there a lot of excess stuff in TCP that won't likely be needed? And if so, can it be removed?
[07:56] <McGooch> So say the king wants to send a message to another lord. He tell a servant, the servant tells the pidgeon master, the pidgeon master sends birds
[07:56] <TechnoCat> it can only be removed by reimplementing it
[07:56] <EntranceJew> not for a proper implementation of TCP
[07:57] <TechnoCat> just use tcp and be happy with it for now
[07:57] <TechnoCat> instead of getting lost in a curmugeoned mess of UDP
[07:57] <McGooch> UDP is the dumb pidgin, TCP is the pidgin master that cuts up the kings message and sends it.
[07:57] <Codex> (excellent example with the pidgeons, btw)
[07:58] <EntranceJew> dress UDP up like TCP and win a prize
[07:58] <McGooch> If you change the rules, then its not TCP anymore. Its a different protocol. Which is fine so long as both the sender and receiver know that.

Enjoy! :3
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: UDP vs TCP (networking)

Post by slime »

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: UDP vs TCP (networking)

Post by Robin »

Ah, the Pigeon Master... it's been a while since I've played Pigeons and Dragons.
Help us help you: attach a .love.
User avatar
Pigeon
Prole
Posts: 29
Joined: Sat Oct 05, 2013 9:37 am

Re: UDP vs TCP (networking)

Post by Pigeon »

For some reason this came up as a quote of me :D I am ze pigeon!
If I seem aggressive, It's because of my head. Not me. Please do the best you can to deal with it, it's not my fault I'm the way I am. :)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests