Peer to Peer networking

Started by
28 comments, last by nivlekio 16 years, 1 month ago
Hey all! Im working on a uni course work project with 6 other guys making a real time strategy game, and I choose to do networking ( bad idea lol ). I have done some tutorials on win sock but cant find nothing on peer to peer stuff. Basically since its a uni project I wont be able to have a dedicated server which would make a lot easier. I want to create the peer to peer model for when the user enters the LAN or Internet network lobby, this is where they will see all the other players and hosted games. I am stuck on how to model this. I have a fair idea of what to do but I am lost in some areas. So far I have created a thread for the listing, once a peer connects to the binded port they are accept and are set to a different port. When the peer is accepted a packet is sent to them telling the info of the person they have connect to such as their name, lobby status (hosting, lobby, client in hosted room). I am stuck on the connecting bit “ ClientSocketObject.Connect() ” I don't know how to word this but I will try my best, how on earth do I search for the users IP address whom I want to connect to on the lobby? Also how do you go about sending a struct (if possible) and receiving it as a struct in stead of a char buffer?
Advertisement
RTS games (because of the large amount of units) most often solve this with "lock-step-simulation". i.e. we synchronize our logic frame updates exactly between clients and all random number generation is guaranteed to return the same results on different clients (to ensure that the same simulation happens on each client). You can achieve the latter by passing around a common seed before simulation begins.

With this solution the only thing you have to pass across the network is user input and some checksum data to ensure that the simulations are synchronized.

This solution also means you need to start building the engine with this in mind from the very beginning: it controls how the entire main-loop works and such.

The RTS game I worked on basically had you updating one logic frame into the future and your current render frame is interpolated from the "last frame" and the "next frame" results. The ends up giving the user 1-logic frame duration of lag between input and unit response; we were running i think 16-20 logic frames per second so this fell within acceptable perceptual delay.

If you go peer-to-peer: which really means you assign 1 client randomly to be the server (or you do bandwidth tests and pick the one with the best upstream). However, as I said, you generally have asstons of units and as a result this route is going to have lots of problems with network lag.

-me
//edit didn't realize this was for a LAN, but meh. good code for anyone.

PHP and a simple mysql DB can handle lobby servers. (everyone I know has web hosting, so this isn't usually a problem)

RegisterServer.php
http://rafb.net/p/v9MK2q77.html
UpdateServer.php
http://rafb.net/p/I0VDoi18.html
ServerList.php used by the clients go see a server list
http://rafb.net/p/DaVwZm27.html

table:
ip int(11)
time int(14)
name varchar(255)
latency int(11)
playercount mediumint(9)
maxplayercount mediumint(9)

here's a tutorial on packets that will get you started fairly quickly:
http://gpwiki.org/index.php/Binary_Packet

just set up a format and send. You didn't say the language, but I have binary packets for a few languages.
The Forum FAQ answers your questions, pretty much.
enum Bool { True, False, FileNotFound };
Thanks for the help but im still lost on the lan lobby bit of the game. If you have played any RTS games on lan like Starcraft, you enter the lobby and you can see if any one has hosted a game to play.

How would you go about coding, code to find an unknown ip of some one who is also playing the game?

Ive been searching alot on this but cant find anything.
Im using winsock btw
Quote:Original post by nivlekio

How would you go about coding, code to find an unknown ip of some one who is also playing the game?


The one "also playing the game" contacts the central lobby server, and thereby provides the IP/port information.
whoever initiates the connection with host (the machine responsible for accepting new players) gets his public address (address behind his NAT, local IP address for LAN, ...) sent to other peers by the host. Then the peers can talk to each other.

That's pretty much it. Why cant you have a dedicated server anyway?

Everything is better with Metal.

Lobby works like this:

1) centralized server to act as matchmaker
2) client hosts game
3) in hosting a game, the engine contacts the central server which throws your IP and game into the shared lobby space (database)

4) now connecting clients, entering the lobby have access to the hosted games.

You can't do a lobby without a centralized, known server.

-me
Quote:im still lost on the lan lobby bit of the game


Q21) and Q24) in the Forum FAQ answer your question.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement