How to connect two or more different devices to a server in Godot 4.2.1 (Multiplayer Game)

My game has a LineEdit node to type on the IP address, the problem is when I connect the both devices in the same server, but either in my Android phone or my computer with Windows 11 the player who already connected to that IP address does not appear, how can I fix that through code? Because I already connected the IP of my router to the program.

You will not connect both devices to the same server, one device will be the server, and the other connects to that device. Your router’s IP address is not part of the equation, and should not be present.

You could add more error checking to this process by using the create_client’s return value, using your last posted script, this would give an error if it cannot connect

func _on_join_button_pressed():
	$"Multiplayer Mode".visible = false
	$"Join Game".visible = false
	var connect_error := peer.create_client(DEFAULT_IP, DEFAULT_PORT)
	if connect_error == OK:
		multiplayer.multiplayer_peer = peer
	else:
		push_error("Failed to connect to %s!" % DEFAULT_IP, connect_error)
1 Like

I still have the same problem, when I put on my default IP address in my phone and my computer with the game executing, I can’t see any player in the level when I join the created game.

connect multiple devices to a server in Godot 4.2.1 for a multiplayer game, use the Multiplayer API to handle connections and synchronize game states across all clients and the server.

The next issue I see is how you setup the multiplayer signals. They should be connected before you create your server or client.

See this doc

This is an example from the page. They setup the signals in ready function.

func _ready():
	multiplayer.peer_connected.connect(_on_player_connected)
	multiplayer.peer_disconnected.connect(_on_player_disconnected)
	multiplayer.connected_to_server.connect(_on_connected_ok)
	multiplayer.connection_failed.connect(_on_connected_fail)
multiplayer.server_disconnected.connect(_on_server_disconnected)