How to connect two device with live server ip, not a localhost in Godot 3.1?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Shailesh dhaduk

I a’m using Godot 3.1. Creating two player game, one player own and second player is server(other device player).

Now how to connect two player with live server network?

I a’m creating one demo of two player connect each other and it’s working find in local server ip and port 4242.

I see both Godot project demo but it’s also work in local ip, demo link are below.

:bust_in_silhouette: Reply From: wombatstampede

Your question is a bit unclear. In your title you state that you want to connect two devices with a live server. So you’re speaking of three devices or at least programs.

Inside your question you state the the second player IS the server. That would be a kind of peer to peer (P2P) network approach.

First of all. Godot offers some different multiplayer network options. You also can either connect two clients to a server (all running godot) or let one device be the server.

Second: Forget about localhost/ (not 0). This is a virtual local address and only works when all software runs on a single device.

Third: There are multiple ways to connect two devices via the network of with another server. And there are also potential problems depending on what you want to achieve.

Classic Client-Server:
You can have a server software running on a hosted server. This server usually has at least an ip or even a domain/hostname mapped to it. The hosting package has to allow running custom software on it though. It is also possible to run such a server on an own device an configure your router port mapping and dynDNS so that external users can access the port+device from outside.
Some info about godot servers:

Local network:
You can have both clients running in the same network. If the network allows two clients “speaking” to each other (often not the case in public wifi networks) then you can simply let one client be the server and access it via its local ip + port (such a local IP often begins with 192.168.).

Port mapping or UPnP:
If the router is (manually) configured the forward a port to the specific “server” device IP the client can connect to the dial-in IP of the server (this is the temporary IP that is assigned to the router on dial in) + port. Or the router can be configured via UPnP to do the port mapping (but not all routers allow this for obvious security reasons):

If both clients access the internet via IPv6 then they might both have world wide unique IPv6 addresses to adress each other. (As long as the router/firewall allows it).

NAT punch through:
In IPV4 networks there’s a method to circumvent the portmapping/address dilemma which occurs with routers when both clients are in different local networks. You’ll still need a hosted server + software to initiate the client<->client communication but the server won’t need to route/proxy the traffic.
See this answer:

Thank your for quick give me answer.

First clear my question,
One app is Godot install in two devices (iOS or android) both connect with internet not a local network,
Now how to connect both device with server so one device move object on that time reflect in second device.

This point related any doc or source part or any link provide here.

Shailesh dhaduk | 2019-04-15 11:07

I faced a problem you might know the solution to. I need a simple way to update one value across all devices.

If a < b:
    b = a
    "update b in all devices that has this app installed (either while being played or closed, doesn't matter)" 

Thank you for your time!

Suleymanov | 2020-12-28 11:36

For a function, you must first create it as a sync function.
Sync func myFunction():
Then, you must call it with:

GarterSnake502 | 2021-05-03 16:49