How do UPD connections to two peers behind a switch work? (and other questions)

Started by
2 comments, last by hplus0603 12 years, 1 month ago
So for school I got my team to agree to making a networked game. It's going to be a top-down 2D zombie shooter (arcade style), and I think I'd prefer to use UDP over TCP simply for the sake of less lag and stutters. I've also never worked with UDP so this is proving to be a good learning experience. I've got a series of questions though that I didn't find in the FAQ that I hope you can help with:

[color=#ff0000]1. I assume most lobby stuff is done using TCP, correct? (i.e. finding a game) If not, why not?
I've read that UDP is often used in LAN stuff to discover games though... is there a common way to abstract this to minimize the logic required to find games over LAN or over the great Internet? Also, I'm not worrying about authentication/secure login in this question.
[color=#ff0000]2. Once a game has been found, how can each player be distinguished?
I'd like one player to act as host and all other players to be clients of the host. I assume that once a game is found from the Mother Server, the Mother Server passes the IP address to all the players of that game and blesses one as the host. How can two players who might be behind the same switch be distinguished by the host? Does the Mother Server also generate a unique session ID for each player (this is why I assume TCP is used in the lobby stuff), and that unique session ID is sent in the message to the corresponding player (and if the player gets a message that doesn't contain its unique ID, it ignores it)?
[color=#ff0000]3. How do I determine a player has disconnected?
I assume here that there is a minimum update period set, and if a player doesn't send an update within a certain number of seconds, they are considered disconnected. Is this how it's normally done?

I think those are the core questions I have for now. If I get more I'll ask later in the thread. I'd really appreciate any help here!
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
The FAQ has some fantastic resources linked, which would answer these questions pretty well.

However, in brief:
1. You typically want to do lobbying and matchmaking using the same (or similar) protocol as for the game.
2. Players are distinguished by their source IP address and port number.
3. A player has "disconnected" when you haven't heard anything from that player in N seconds.
enum Bool { True, False, FileNotFound };
Thanks. I'm not too familiar with networking jargon (like NAT punch-through), so there's probably more effective ways to word my questions.


1. You typically want to do lobbying and matchmaking using the same (or similar) protocol as for the game.

Cool, cool.


2. Players are distinguished by their source IP address and port number.

I reread the FAQ and I think NAT punch-through actually covers some of the complications I was worried about (you've got a nice article on it, btw). It two players are behind the same router, but playing with a 3rd player behind a different router, the first router gives the two players each a unique port, and that's how I can distinguish the two? Also, when is port-forwarding on the router necessary? Do developers require port-forwarding to be used when either NAT punch-through isn't used, or also when NAT punch-through wouldn't work?


3. A player has "disconnected" when you haven't heard anything from that player in N seconds.

Great.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
[indent=1][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

the first router gives the two players each a unique port

[/font]




[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

Correct.

[/font]


[indent=1][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

when is port-forwarding on the router necessary?

[/font]



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

When a server/host is behind a NAT gateway and you're not doing punch-through using an external introducer, and/or punch-through ends up failing. Port forwarding is only for hosts/servers. For a school game, don't worry about punch-through, unless that in itself is the main goal of the project.

[/font]

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement