I've been testing and making a multiplayer game using localhost, but when I added port forwarding I have a couple weird issues. Firstly is that they cannot connect to each other over two different computers. But if you open two tabs on the same computer and leave the adress entry empty, they connect as if using localhost. But if you enter the external facing adress, it won't connect to the server. The documentation says create_client() needs a ipv4 or ipv6 adress, mine is in the format of ...* I'm confused if that is the right format or not. I have the networking code on an autoload and call signals from other nodes in the game. Here is the code for the network.
extends Node
var network = ENetMultiplayerPeer.new()
var external_ip
var port = 9999
signal peerConnected(peer_id)
func start_server():
network.create_server(port)
multiplayer.multiplayer_peer = network
multiplayer.peer_connected.connect(peerConnect)
var upnp = UPNP.new()
var discover_result = upnp.discover(2000,2,"InternetGatewayDevice")
if discover_result == UPNP.UPNP_RESULT_SUCCESS:
if upnp.get_gateway() and upnp.get_gateway().is_valid_gateway():
var map_result_udp = upnp.add_port_mapping(port,port,"godot_udp", "UDP", 0)
var map_result_tcp = upnp.add_port_mapping(port,port,"godot_tcp", "TCP", 0)
if not map_result_udp == UPNP.UPNP_RESULT_SUCCESS:
upnp.add_port_mapping(port,port,"godot_udp","UDP")
if not map_result_tcp == UPNP.UPNP_RESULT_SUCCESS:
upnp.add_port_mapping(port,port,"godot_udp","TCP")
external_ip = upnp.query_external_address()
func join_server(adress): #The adress is external_ip typed in from a different computer
network.create_client(adress,port)
multiplayer.multiplayer_peer = network
func peerConnect(peer_id):
emit_signal("peerConnected",peer_id)