Asynchronous TCP connection on Godot3

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By henriquelalves
:warning: Old Version Published before Godot 3 was released.

I’m having trouble setting up an asynchronous TCP connection with a server I created; what I’m currently doing is:

  1. Creating a new StreamPeerTCP object on my script.
  2. Use streamtcp.connect_to_host(server_ip, server_port)

The server-side looks correct (a new tcp client shows up), but on Godot I can’t seem to find any way to set signals for successful StreamPeer connections nor signals for receiving packets - I’m currently having to rely on _process to check when the connection state of the StreamPeerTCP ever changed, and the SceneTree signals networkd_peer_connected and connected_to_server doesn’t seem to trigger ever. Is this a bug?

Actually network_peer_connected and connected_to_server are signals from the high level API. When you use StreamTCP.connect_to_host() it returns an error code that is OK or FAILURE. You can get the status of the connection with the method StreamTCP.get_status() that returns the status of connection. See https://docs.godotengine.org/en/3.1/classes/class_streampeertcp.html

So, it is not a bug, you just dont use signals with this API.

Paracrazy | 2019-04-11 02:51