No errors, but connected_to_server not emitted

Hi!
I’m using Godot 4.2.1 and am dipping my toes in networking. So far, I have my phone “connect” to my laptop using the following script:

func _ready():
	multiplayer.connected_to_server.connect(server_connected)


func _on_join_pressed():
	var address: String = %Address.text
	var port: int = int(%Port.text)
	var error = MultiplayerHandler.join_server(address, port)
	if error:
		OS.alert(error_string(error) + " (" + str(error) + ")")
		return


func server_connected():
	get_tree().change_scene_to_file("res://menus/pre_start_menu/pre_start_menu.tscn")

Now, as you can see, I catch any errors and show them using OS.alert(). This doesn’t happen, so the multiplayer_peer gets created correctly. But the connected_to_server signal doesn’t get emitted, and nothing comes up on my server too.
Here’s also the MultiplayerHandler, which is an autoload:

extends Node

# Returns error
func join_server(address: String, port: int):
	var peer := ENetMultiplayerPeer.new()
	var error = peer.create_client(address, port)
	if error:
		return error
	multiplayer.multiplayer_peer = peer

Yeah, I basically copied it from the docs.
So, yeah, I really don’t know where the error could be.

I just did a sanity check for you and ran your code in a blank project of mine (on Windows) and it ran fine and emitted server_connected just like it should.

The one thing that comes to mind and I have no idea how exporting and running on Android works, assuming the client is android based on tag. Make sure INTERNET permission is passed or Android will block it. See here yellow warning down a bit. At least something to check.

2 Likes

And once again the bug was just me being stupid.
On the client, I just typed the IP address that would come up when I ran ip addr on my computer. It seems though that I don’t really understand the output of the command, because that wasn’t my IP address. After looking the correct address up in my router, the connection now works.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.