connect_to_host always return 0 even it's not connected

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rico345100

Here’s the code for connect localhost server.

export (String) var host = ''
export (int) var port = 1337

var client: StreamPeerTCP

func _ready():
	client =

	var error = client.connect_to_host(host, port)
	print(error)  ---> Always return 0

error always have 0 (OK), regardless server is online or not.

In server, when Godot Game runs and try connect_to_host, connection established both server and godot without any problem.

Is this glitch or something? Using Godot 3.2.rc3.official release.

:bust_in_silhouette: Reply From: stormreaver

This is how I treat it, based on experience:

connect_to_host is non-blocking, so it doesn’t wait for the connection to succeed or fail. I think of connect_to_host as a connection request, which could succeed or fail at some future point. The result code says nothing more than whether the request succeeded or failed.

I use get_status() in the _process() function to monitor the state of the connection.