Reputation: 23
There is a simple game with multiplayer, but the multiplayer will only work in the local network or on devices with a dedicated IP-address. Is it possible to make multiplayer over the Internet. As I understand it, you need to write a relay server for this or is there another way.
Sorry for my bad English.
Upvotes: 1
Views: 967
Reputation: 48
You can use UPnP. Here is an example code:
var upnp = UPNP.new()
var err = upnp.discover()
if err == OK:
if upnp.get_gateway() and upnp.get_gateway().is_valid_gateway():
upnp.get_gateway().add_port_mapping(PORT, PORT, "GAME_NAME Multiplayer", "UDP")
upnp.get_gateway().add_port_mapping(PORT, PORT, "GAME_NAME Multiplayer", "TCP")
else:
push_error("UPNP error: %d" % err)
This code should only run for the server. One disadvantage of UPnP is, that is must be enabled on the router, so only peoples that have UPnP enabled, can host a multiplayer game over the full internet (Other can host too, but for they it only works in the LAN).
Sorry for my bad English.
My english is bad too.
Code from https://github.com/JanoSemi/VoxelFun/blob/main/scripts/Network.gd
Upvotes: 0