Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gdevelop5:all-features:p2p [2020/07/13 01:43] greench [Peer-to-peer] |
gdevelop5:all-features:p2p [2020/12/26 13:56] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
# Peer-to-peer | # Peer-to-peer | ||
- | <note important> | + | <note important> |
- | GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. | + | GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. |
- | <note warning> | + | <note warning> |
+ | |||
+ | As such, it is hard to verify if someone is cheating (unlike dedicated servers). P2P supports a maximum of 250 simultaneous connections, | ||
+ | |||
+ | ## Selecting a broker server | ||
+ | |||
+ | A running game, called a **client**, must connect to other clients before being able to send data. For this, it needs a way to self-identify and find other clients. To do so a **broker server** must be configured. It's a server with a fixed, well-known address that stores all the addresses of the connected clients and give them to each client, so that they can connect to each other. | ||
+ | |||
+ | There are two options for setting up a broker server: | ||
+ | |||
+ | * Setting up a custom server (recommended), | ||
+ | * Using a default, public server. | ||
+ | |||
+ | #### Set up a custom (local) server | ||
+ | |||
+ | A local server can be set up easily. | ||
+ | |||
+ | Open a command line. To do so on Windows: | ||
+ | - Press the **Windows** and **R** keys. This will open the **run** window | ||
+ | - Type **cmd** in the popup. | ||
+ | - Press the **enter** key. | ||
+ | |||
+ | After opening a command line, complete the following: | ||
+ | - If this is the first time completing these steps, to install the server type **npm install peer -g** | ||
+ | - After the server is installed, and every subsequent time (to start the server), type **peerjs -p <the port> | ||
+ | | ||
+ | Other options can be passed to the PeerJS server, see [its website](https:// | ||
+ | After the above has been completed, the **Use custom broker server** action is used to connect to the server. | ||
+ | * **localhost** can be used as the host address to point to the local server. | ||
+ | |||
+ | <note tip>Note that this is a local server, so it will only work on your machine. When releasing your game you will need to deploy one to a Node.js compatible hosting, like Heroku.</ | ||
+ | |||
+ | #### Use the default server | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | You can also use the default server provided by PeerJS. | ||
+ | To use that server use the action "Use the default server" | ||
## Connecting | ## Connecting | ||
- | For connecting one or more instances, you need to enter the ID of one of them in the others. The ID can be found with the expression `P2P:: | + | To connect |
+ | |||
+ | ## Interacting with connected games | ||
+ | |||
+ | Once you got connected, you can trigger actions remotely. You can select another specific game instance (using its id) or send an event to all connected instances. | ||
+ | |||
+ | ### Choosing if you want to activate data loss mode | ||
+ | |||
+ | You might be wondering what the "data loss" parameter is for. | ||
+ | Due to how GDevelop is made, only one occurence of a remote event can be handled when the event sheet is executed (this happens roughly 60 times per second). To help optimize events execution, we provide the choice to use the dataloss mode. | ||
+ | |||
+ | * With the *no dataloss* mode, every remote event is queued, and on every frame if there is one in the queue, we take the oldest one and handle it. **This makes sure every data is processed/ | ||
+ | * With the *dataloss mode* activated, it doesn' | ||
+ | |||
+ | |||
+ | Here are two examples: | ||
+ | * if you use a synchronised score counter, you don't want to lose any data, as missing only one point of the counter would *desynchronise* the counters, so the dataloss mode would be deactivated. | ||
+ | * If you want to synchronise positions, only the last position sent is relevant, not older positions. In this case, you would activate the dataloss mode *to prevent delays/ |