0 votes

Here's the code for connect localhost server.

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

var client: StreamPeerTCP

func _ready():
    client = StreamPeerTCP.new()

    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 connecttohost, connection established both server and godot without any problem.

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

in Engine by (134 points)

1 Answer

0 votes

This is how I treat it, based on experience:

connecttohost is non-blocking, so it doesn't wait for the connection to succeed or fail. I think of connecttohost 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.

by (190 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.