Ok, I'll add more context. This component works against a server in the same network, which is my domestic WiFi network -- discard the possibility of any firewall blocking my connection or related stuffs, and also I'm not attempting any internet (i.e. out of my network) connection. The loop looks like this:
# Please assume all the signals I use here, exist.
var _stream : StreamPeerTCP = StreamPeerTCP.new()
func _wait_socket_status(statuses : Array):
"""
Waits until the status is in a certain set of values.
This is a co-routine that must be waited for.
"""
if len(statuses) == 0:
return
while true:
await self.after_poll
if _stream.get_status() in statuses:
break
func _data_arrival_loop():
"""
Performs a data arrival loop to read data from this
socket. This also processes the response accordingly.
This is a co-routine that must NOT be waited for.
It must be invoked when the session is starting.
"""
emit_signal("debug_data_loop_started")
await self.after_poll
while _stream.get_status() == StreamPeerTCP.STATUS_CONNECTED:
if _stream.get_available_bytes() > 0:
var response = _stream.get_data(_stream.get_available_bytes())
_my_method_to_process_the_response(response[1])
await self.after_poll
emit_signal("debug_data_loop_ended")
func connect(host):
var error = _stream.connect_to_host(host, 2357)
if error != OK:
emit_signal("session_failed", error)
else:
emit_signal("session_starting")
await _wait_socket_status(StreamPeerTCP.STATUS_CONNECTED)
# And then I launch the loop asynchronously:
_data_arrival_loop()
func _process(d):
socket.poll()
emit_signal("after_poll")
The problem is that suddenly the socket enters in error status, and I don't get why is that error status at all, also. I'd like to understand better to whether that error status is recoverable or should I start over, and stuff like that.