Advertisement

P2P Networking

Started by October 21, 2004 08:47 AM
3 comments, last by wyrzy 20 years, 3 months ago
Ok, I'm sort of new to networking, but I've been learning it as my friends told me I should put it into my next game. The point I'm at currently is to be able to make and understand a small client/server chat app. I'm starting out very simple, and the game is going to be a tetris-clone, but with netplay.
The question is, do you think that a Peer-to-Peer network setup will work. Due to the fact its going to be tetris, I think I can get away with TCP, as the amount of data I'm sending back and forth will be very small. I also need guaranteed delivery, so I really don't think I could use UDP. I ran a test app of sending data between client server, and it was only accurate 90% of the time (Note: I'm using SDL_Net so it runs on Win32 and Mac -- Enet looked nice, but I don't think it runs on Mac; am I wrong?).
Some things about the game: -Max players will be 4 (starting with 2) -I want players to be able to join in the middle of the game, meaning you could start a game against the computer, and then somebody on the net could jump into the game and take control of the computer (instead of having all players join at once) -I also want to have the ability for a player to leave the game, but the person he was playing against will now just have computer AI to play against. (do you think theses expectations are reasonable?)
I don't think I can use a client/server setup, because if I make player1 always the server, then if player1 left, the everyone else would have to leave the game. Do you think this is true, or is there some way I could make a different player the server if the player who's currently the server leaves.
From what I've read about true P2P setups, each computer functions as a server and a client, is that correct? BTW, does anybody know any good examples of true P2P networking in games, or even a website explaining the idea (it would help much)?
I realize that TCP and P2P is rare in most games. [attention]But the question is, do you think this Peer-to-Peer setup will work, and does anyone know of a website that would help me get started? By "get started", I mean like do all my servers need to accept connections over different ports? In the client/server app, I only used one port to accept all clients. Other differences between P2P and client/server are what I'm trying to figure out to get myself started.
I highly recommend Network Programming for Microsoft Windows, Second Edition by Jim Ohlund and Anthony Jones.

Kuphryn
Advertisement
I looked at the Table of Contents on amazon (they have the "Look Inside" the book, and I didn't see much about peer-to-peer networking. Does the book talk about this? Most of what I saw in the contents was client/server setups for TCP and UDP. I am looking for a good start so I could set up a peer-to-peer networking system for my game. Does anyone have any idea about refrences/websites explaining peer-to-peer networking?
Setting up a P2P (TCP) network isn't all that much different from coding a client-server app. Any computer accepting connections will use the same port to listen for the connection. Anytime a computer needs to open a connection to another computer, it will need a different port.

In any case, for your situation, I would probably still opt for a client server approach. To handle the situation where the server may go offline, you could do the following (or something similar).
1) Server sends out the IP/Port information of all the clients TO all the clients (Clients will just store this information)
2) Along with that information, the server sends out a ranking system of the clients
3) When server goes offline, the 'highest' ranked client knows that it should now be the server and listens for incoming connections.
4) All other clients should attempt to connect to the 'new' server.

Michael Brennan, Ph.D.
Quote:
Original post by mbrennan
In any case, for your situation, I would probably still opt for a client server approach.

Ok, I think I understand the idea of switching the server to one of the clients when the original server leaves, but any reason for going with client/server as opposed to P2P? I've got the game set up as P2P, and its fine as long as people are not behind a NAT, and for that reason I probably will need to switch it to a client/server.

I've read threads saying that Punch-Through for NATs only works with UDP, and not TCP - but due to the nature of the game, I need guaranteed delivery, packets must arrive in the order they were sent, and data must not be currupted. I could probably implement that myself, but it would probably be even slower than TCP, don't you think?

The only reasons I can think of for the client/server approach are that if there were clients behind a NAT, then they could still play, and there would be also less data to send back and forth. However, besides explicity asking the player if they can accept incoming connections, is there any way to determine whether the player is behind a NAT?

One other quick question, if people were behind a NAT, does anyone know if there would be a way for them to connect to a true P2P application? I've read a few threads about this, and the quick answer was no, but I thought I'd throw it out there just in case someone had an idea how to do a P2P game when both people are behind a NAT.

This topic is closed to new replies.

Advertisement