GodotSocketIO
GodotSocketIO copied to clipboard
Successfully connects, but only after ~60 seconds.
It seems that it works perfectly fine in the browser during remote debug or web export, but when you run your game in the editor, it doesn't connect-- at least not immediately. You have to wait for around a minute, and only then does my server receive the connection and fire its connection event
I'm using express.js+socket.io 4.8.1
my client code (using most of the example in the repo)
class_name NetworkClient extends Node
var client = SocketIOClient
var backendURL: String
@onready var game: Node3D = get_node("../Game")
func _ready():
print("Test") # this fires immediately when the game boots up
# so it's not like the scene tree loads late
# prepare URL
backendURL = "http://localhost:3000/game"
# initialize client
client = SocketIOClient.new(backendURL);
# this signal is emitted when the socket is ready to connect
client.on_engine_connected.connect(on_socket_ready)
# this signal is emitted when socketio server is connected
client.on_connect.connect(on_socket_connect)
# this signal is emitted when socketio server sends a message
client.on_event.connect(on_socket_event)
# add client to tree to start websocket
add_child(client)
func _exit_tree():
# optional: disconnect from socketio server
client.socketio_disconnect()
func on_socket_ready(_sid: String):
# connect to socketio server when engine.io connection is ready
print("Socket ready")
client.socketio_connect()
func on_socket_connect(_payload: Variant, _name_space, error: bool):
if error:
push_error("Failed to connect to backend!")
else:
print("Socket connected")
func on_socket_event(event_name: String, data: Variant, _name_space):
match(event_name):
"chunks":
PacketHandler.chunks(data)
func send(event: String, data: Variant):
client.socketio_send(event, data)