Handle reconnection for godot-socketio#7
Conversation
- Implement reconnect logic - Handle _on_noop
godot-socketio
godot-socketiogodot-socketio
|
Thanks again for this amazing addon @msabaeian, thanks to you, I could make my card game so much more reliable. If this PR makes sense to you, I am really happy to contribute; otherwise, I will remain on the fork I have. Thanks again for taking care of such a complicated problem |
[FEATURE] Implement reconnect and noop handler
|
Hey @garciaf! thanks for your work! I’ll review this in the coming week and if everything looks good, merge it. |
|
All good @msabaeian if you want to review it in the game I am working on, I can give you further access to the prototype I have. But basically, I use this plugin to allow people to play the Godot game on their phone (With a web browser). And Socket IO is so much more reliable than Websocket. Your work is incredible. |
msabaeian
left a comment
There was a problem hiding this comment.
thanks for your effort, i've some question and suggestions
|
@msabaeian thank you so much for looking into it, and very good comment. I will fix it and push it. We might also consider changing the Readme afterward. |
| var t := Timer.new() | ||
| t.wait_time = reconnect_base_delay_seconds * _reconnect_attempts | ||
| t.one_shot = true | ||
| t.timeout.connect(_emit_reconnection_attempted) |
There was a problem hiding this comment.
@msabaeian does the emit event work when it is done this way?
I did not want to change the other method engine_make_connection to avoid having this event emitted for other reason.
|
@msabaeian thanks for your patience with your comment and feedbacks. I took care of all comments and did my best to answer the questions to the best of my abilities. I tested this version on my game; nothing to report so far. Hope that would work for you |
|
The code looks good to me, I need to run a test on my system then merge, thanks for your effort! |
|
Hi @garciaf I tested this on Godot and unfortunately it does not work for me, my steps are:
|
|
@msabaeian very good catch. I also used the opportunity to give some explanation on how to test in the README.If you want, I could put this part in a different place. But I think it would be useful to have a small guide on how to test your development yourself I made the fix. Maybe you have a different setup for testing your addon; if that's the case, feel free to correct the assumption I made in the README.md I tested the scenario you found, and it works now with the change |
|
@garciaf could you please mention your test steps and maybe attach a video of it? i tested again and it's not working still |
Bug fixes
_on_noop()treated NOOP as an errorNOOP is a normal Engine.IO packet sent during polling to unblock a long-poll request. The handler was calling
push_error(). It now calls_poll(), matching the behaviour of_on_message().disconnect_socket()emittedsocket_disconnectedtwicedisconnect_socket()calledengine_close()which already emitsengine_connection_closed→_on_engine_io_connection_closed()→socket_disconnected. The duplicate directsocket_disconnected.emit()at the end ofdisconnect_socket()was removed.Upgrade PONG and heartbeat PONG not distinguished
_on_pong()was unconditionally triggering the WebSocket upgrade flow. It now receives the raw payload and only upgrades when the payload is"probe", correctly ignoring plain heartbeat PONGs from the server.StateandTransportTypeenum type annotation errorIn Godot 4, inner enums on a
class_nameclass cause a type mismatch between the unqualified (State) and fully qualified (EngineIO.State) names when used as type annotations. Removed the explicit type annotations onstateand_transport_type, letting GDScript infer them from their initialisers.Client-initiated PINGs broke Engine.IO v4
In Engine.IO v4 only the server sends PINGs — client-initiated PINGs are v3 behaviour and cause the server to disconnect with
transport error. A heartbeat timer that was sending unsolicited PINGs onpingIntervalhas been removed. The existing_on_ping()→ PONG response path is sufficient for keepalive.New feature: automatic reconnection
When the WebSocket closes unexpectedly, the client now attempts to reconnect automatically with linear backoff instead of immediately calling
engine_close().Three new exported variables are exposed in the Inspector:
auto_reconnecttruemax_reconnect_attempts5reconnect_base_delay1.0A new signal
reconnect_attempt(attempt: int, max: int)is emitted on each retry so the game UI can show feedback like "Reconnecting 2/5…".On a successful reconnection
_reconnect_attemptsresets to0at both success paths (polling in_on_open, WebSocket in_on_pong). If all attempts are exhausted,engine_close()is called normally andengine_connection_closedfires once.