Open digimbyte opened 3 months ago
the current issue is that it keeps creating new clients and no way to keep it open
The way you created WebSocketClient requires you to periodically call the poll function, for example from the _process function, that is the reason why the connection is closed, add the following to your code:
func _process(_delta: float) -> void:
socket.poll()
I am currently using the NodeWebSockets plugin for Godot and have encountered some challenges. Specifically, I need help with the following:
Setting Up Scripts as Singletons
The documentation is not clear on how to properly set up WebSocketClient and WebSocketServer scripts as singletons. Could you provide a detailed example of how to do this correctly?
Handling Ping/Pong Messages
I am having issues with handling ping (
2
) and pong (3
) messages within the_on_message_received
function. The connection frequently closes after receiving a ping message, and I am not sure if I am responding correctly.Example Code:
Here is a simplified version of my current WebSocketClient script:
Simplified Node.js Script
I also need a simplified example of a Node.js server script that can interact with this client. Specifically, how to correctly handle the WebSocket handshake and the ping/pong mechanism.
Example Node.js Server:
Any guidance or examples would be greatly appreciated.
Thank you!