Client can't connecet over different computers, even with port forwarding
Asked Answered
S

3

0

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)
Scever answered 20/4, 2023 at 2:10 Comment(0)
S
0

I found a fix,

I opened the windows command prompt and used "ipconfig" which gave me a whole list of different things. I found the IPv4 adress there and when I hosted a server and added that as the adress to connect to, it worked. It's not perfect because I would prefer it to work in game, but since I'm mostly only making this for me and my friends, I'm just glad it will work at all.

Scever answered 20/4, 2023 at 19:45 Comment(0)
M
0

If you router is set on DHCP, your IPV4 adress will change, you might want to set a permanent adress on your router to use when hosting your server.

Muggy answered 21/4, 2023 at 14:19 Comment(0)
S
0

Muggy Thank you for your reply!!

Scever answered 22/4, 2023 at 5:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.