• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

P2P Networking

C

Cakyro

Guest
Hi.
I'm trying to figure out how to make P2P connection.
I have found no information, most of the documentation and tutorials use a server-client architecture, with different projects for the server and client or having a client to host the server.

Thanks in advance.
 

chamaeleon

Member
Hi.
I'm trying to figure out how to make P2P connection.
I have found no information, most of the documentation and tutorials use a server-client architecture, with different projects for the server and client or having a client to host the server.

Thanks in advance.
In many cases you need a server (your own or some third party) to make P2P work, due to firewalls and NAT preventing direct connections from one game instance to another. Just about the only case you don't worry much about it is for local LAN connections.
 

johnwo

Member
You can either:
Use the IGD protocol for NAT traversal (IGD is implemented via UPnP) to temporarily open ports to which remote clients can connect to. Not all routers support this.
Use NAT-Punchthrough (hole-punching). requires a server.

Once you have this in order, you can implement:
A Server/Client-setup with host-migration; easy to implement, lower latency, you can easily pick the client best fit for being the host.
A true P2P setup; hard to implement, one player with high ping affects every player, higher latency, security challenges, no central authority to validate data (this makes cheating easier).

I would recommend a Server/Client setup with host-migration, it's sort-of the best of both worlds.
True P2P (that is, P2P without an authorative server to sanity-check data) is good for data-exchange (torrents, etc.), not so much for games.
 
C

Cakyro

Guest
In many cases you need a server (your own or some third party) to make P2P work, due to firewalls and NAT preventing direct connections from one game instance to another. Just about the only case you don't worry much about it is for local LAN connections.
Can it be solved by port-forwarding? If that's the case, I would rather have the players to do the port-forwarding than setting up a dedicated server.

You can either:
Use the IGD protocol for NAT traversal (IGD is implemented via UPnP) to temporarily open ports to which remote clients can connect to. Not all routers support this.
Use NAT-Punchthrough (hole-punching). requires a server.

Once you have this in order, you can implement:
A Server/Client-setup with host-migration; easy to implement, lower latency, you can easily pick the client best fit for being the host.
A true P2P setup; hard to implement, one player with high ping affects every player, higher latency, security challenges, no central authority to validate data (this makes cheating easier).

I would recommend a Server/Client setup with host-migration, it's sort-of the best of both worlds.
True P2P (that is, P2P without an authorative server to sanity-check data) is good for data-exchange (torrents, etc.), not so much for games.
The problem with UPnP is that Game Maker has no support for it. The only way to solve this is using an extension.
I will take a look at hole-punching.

For the type of game I'm making it's used a Peer to peer architecture because it's needed that all player are in equal conditions so if a player has high ping all players "slow down". I don't really care about cheating because players will decide with what people wants to play.
Also, I want to know why do you think pure P2P is hard to implement because I usually hear the opposite.
 

johnwo

Member
I'm just reponding to each statement/question here separately, disregarding context.

The problem with UPnP is that Game Maker has no support for it. The only way to solve this is using an extension.
You could theoretically just start a UDP server, do a search for UPnP compatible devices with a multicast on port 1900 UDP, wait for response, then if you got a response, just get the IP, send a request for a new port mapping... No extension needed.
Google "upnp http request" or similar to learn more.

For the type of game I'm making it's used a Peer to peer architecture because it's needed that all player are in equal conditions so if a player has high ping all players "slow down".
So, it's just needed for lag compensation, or rather just to keep clients in sync at all times?
Using P2P just to ensure synchronization is like taking chemo because you're tired of shaving your head...


Also, I want to know why do you think pure P2P is hard to implement because I usually hear the opposite.
This depends on what sort of game it is, how much data is transferred, if it's necessary to check clients for desync, etc...
It's hard in the sense that contrary to a traditional server/client-setup, there is a lot of overhead.
When a player connects, you synchronize the clients. During normal gameplay, you have to make sure that the clients stay synchronized, and so on...
This is much easier when clients are handled by an authoritative server.


I don't really care about cheating because players will decide with what people wants to play
This might not pertain to you, but:
Say you have a PvP game where you only play with people you want to play with, or it's a PvE or other sort of player vs. something.
If it's the former, then you might as well go with host-migration, seeing as it is faster and with less overhead.

If it's the latter, you run into a problem with deciding how non-players act.
Say you're making a PvE TDS where you fight trolls: How do you decide where the enemy trolls move? Who do they attack?
You might think that synchronizing random-seeds, etc. will help, but then you run into the issue of latency causing desynchronization.
The only way to ensure that clients stay synchronized in a case like this, is to have an authoritative peer that decides how enemies act; then you're back at traditional server/client with host-migration being the better option.


I'm not trying to discourage you. Who knows, P2P might work for you!
I wish you the best of luck!
 
C

Cakyro

Guest
Thank you for the response!
First, I didn't know anything about the UPnP http request. I was always told that Game Maker had limitations in networking unless you use extensions or create the server in an external language. So hearing that it's not the case it's nice.
I will try what you said and see which is the best for my project.

Maybe I should have talked more about my game. Just tell me which one do you think it would be better for my game:

My game is a simple 4-player platform-fighter game. Examples of thedata that is transferred are the coordinates of the players and the bullets and lives.
 

chamaeleon

Member
Thank you for the response!
First, I didn't know anything about the UPnP http request. I was always told that Game Maker had limitations in networking unless you use extensions or create the server in an external language. So hearing that it's not the case it's nice.
I will try what you said and see which is the best for my project.

Maybe I should have talked more about my game. Just tell me which one do you think it would be better for my game:

My game is a simple 4-player platform-fighter game. Examples of thedata that is transferred are the coordinates of the players and the bullets and lives.
The multicast solution requires the devices being on the same LAN. Is this the case? If so you don't need a server expect in the sense that each client acts or can act like one.
 

kerim

Member
actually you can check this game maker extension;
https://gamemakerserver.com/en/docs/
it's easy to setup and it's client sided, you can send arguments as read them as well from that extension's p2p documents.
but before that you'll also need to connect your game to that server which is free to use game built-in game server.
 
C

Cakyro

Guest
The multicast solution requires the devices being on the same LAN. Is this the case? If so you don't need a server expect in the sense that each client acts or can act like one.
And what if they weren't? What will change?

actually you can check this game maker extension;
https://gamemakerserver.com/en/docs/
it's easy to setup and it's client sided, you can send arguments as read them as well from that extension's p2p documents.
but before that you'll also need to connect your game to that server which is free to use game built-in game server.
I've already known about it but I've never tested it. What if the server closes? Online in games using these will get unusable right?
 

kerim

Member
well it's out there since 2012 i don't think it may close in anytime soon, since there is semi-big games in there such as Blox, Undertale online
 

chamaeleon

Member
And what if they weren't? What will change?
Do you think every device on the entire internet receives a broadcast message if you send one? That's not how it works. On a LAN, a broadcast message will be received by every device one the same subnet, without the need for the sender to specify which device specifically should receive it. This can be utilized for either the entire game play session if your protocol/data being sent allows for it, or can be used for device discovery by having each device receiving it reply back directly to the sender without using broadcast at which point that sender becomes aware of that particular device and also its IP address. If you put devices on different networks, mixing mobile, computers on home networks, players on wifi connections at public hotspots, whatever, there is no solution except knowing the address of something specific to contact. That is either a well-known server address (again, hosted by you, or a third party), or because the players exchange IP addresses (which are not guaranteed to change the next time they decide play with someone) using some means outside the scope of your game. You're putting a big burden your players if you insist on not having a server (with a corresponding known, compiled into your game, address) mediate connections between them.
 
Top