Is there is a way Peer-to-peer in all platforms? (mobile-pc)

Godot Version



Is there is a way to make peer-to-peer connection with godot in all platforms?
I know there is UPNP but it doesnt works on mobile.
Is there is another way?
If ıpv4 cant, maybe ıpv6 do this?
Is there is a way to do it without server?
Thanks! :smiley:

1 Like

The problem with peer-to-peer is that all clients need to be directly reachable, and this can’t be done on mobile connections due to their use of CGNAT or similar features that make their IPv4 not directly routable. Also, IPv6 support on mobile connections isn’t that widespread yet in most countries – and when you do have IPv6, it’s often firewalled with no way for users to opt out of that firewall.

The only alternative you have is to rely on STUN and TURN servers (via WebRTC), but this isn’t supported by ENet.

Also, while some free STUN servers exist, you’ll have to pay to host a TURN server for the ~10% of clients who can’t rely on a STUN server alone. This is because TURN requires much more bandwidth as it relies all traffic through the server, as opposed to using the server only to perform the initial hole punching.

STUN only works in situations where the client has their own IPv4 or IPv6 behind a standard firewall. It won’t suffice for users behind a CGNAT, a mobile connection, or a corporate/university connection with aggressive firewall rules.

1 Like

This is a very complicated topic. Browsers try this for WebRTC video-conferencing:

Maybe you can somewhere find a library that implements this procedure. You would still need TURN servers for some clients though AND you initially need a signalling connection that can relay information between the clients, so they can coordinate while searching for a path.

Thanks for you reply @Calinou
That means without server it cant be done in mobile?
And can I make my STUN/TURN server,
Or can I use a regular website server as STUN/TURN server?

And can you answer this question also: (if you know) Thanks!

Thanks @joviansettler ,
This protocol look interest.
Is there is a tutorial about it or it can be apply to godot?

Have you looked at this: GitHub - libp2p/libp2p: A modular and extensible networking stack which solves many challenges of peer-to-peer applications. ?

There are implementations in different programming languages. Maybe you can encapsulate one of those into an extension for Godot.

Thanks @joviansettler !
I will check it.

Yes of course it can possible. But I dont have enough knowledge with making plugins for godot. If you can show me a tutorial for it, it will help so much :smiley:

I don’t have a lot of experience with extensions either.

One of the available languages for this library is Rust. I have followed this tutorial the other day and the result was an extension that gave me a custom node in Godot:

Getting your plan to work is probably possible, but very complicated.

thanks for your reply @joviansettler ! :smiley:
I found some tutorials about making plugins. I will check what it gives.
I dont know anything about rust but I can try to understand.
But anyway the libp2p looks very interest. Do you have more source about it?

No, I just googled it.

okey thanks

Pure Peer-to-Peer (P2P) Limitations:

  • Godot doesn’t have built-in, reliable P2P across all platforms without a server.
  • UPnP (Universal Plug and Play) for automatic port forwarding is unreliable, especially on mobile due to carrier restrictions.
  • IPv6 doesn’t inherently solve discoverability issues without a server for initial contact.

Alternatives and Considerations:

  1. Relay Servers:
  • Consider using a third-party relay server to facilitate initial connection establishment.
  • Explore options like RakNet, Colyseus, or similar services.
  • Be mindful of potential costs and limitations imposed by these services.
  1. Hybrid Approach:
  • Implement a central server for initial player discovery and matchmaking.
  • Once players connect, have them communicate directly using P2P protocols (UDP or TCP) for real-time gameplay data exchange.
  • This balances discoverability with efficient data transfer.
  1. LAN (Local Area Network) Play:
  • If your game is intended for local multiplayer on the same network, Godot’s built-in UDP networking can work effectively.
  • Players can discover each other automatically within the LAN.

Yes, it is possible to establish peer-to-peer connections across all platforms using Godot. While UPNP is not a reliable solution, especially on mobile devices, there are alternative approaches:

  1. NAT Punching: This method involves using a third-party server to facilitate the connection between peers. The server helps the peers to discover each other’s IP addresses and port numbers, allowing them to establish a direct connection. Godot provides a built-in NAT Punching implementation.

  2. Hole Punching: Similar to NAT Punching, hole punching is a technique that allows peers to establish a connection by sending simultaneous connection requests to each other. This method can be used when both peers are behind a NAT.

  3. Relay Servers: Another approach is to use a relay server that acts as an intermediary between peers. The relay server forwards data between the peers, enabling communication. This method requires a dedicated server, but it can provide a reliable peer-to-peer connection.

  4. Libraries and frameworks: There are libraries and frameworks available that provide peer-to-peer connectivity, such as:

    • libp2p: A decentralized network library that provides peer-to-peer connectivity.
    • Webrtc: A set of APIs for real-time communication over peer-to-peer connections.

Regarding IPv6, it does provide better support for peer-to-peer connections due to its built-in support for end-to-end connectivity. However, its adoption is still limited, and it may not be a viable solution for all platforms.

In summary, while there is no single, straightforward way to establish peer-to-peer connections across all platforms, Godot provides built-in support for NAT Punching, and other libraries and frameworks can be used to achieve peer-to-peer connectivity.

is there is tutorial for check?
for give me a idea or example

This is only the case within its WebRTC support (as it’s essentially required by the WebRTC specification), not when using ENet or WebSockets.

is there is a document or tutorial about it? it looks very interest

Is there is a tutorial or documentation about nat punching in godot? because I cant find about it