Skip to content

Add TaloMultiplayerPeer and multiplayer sample. #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Daylily-Zeleen
Copy link
Contributor

@Daylily-Zeleen Daylily-Zeleen commented Feb 25, 2025

Implemented through Talo Channels.

Need #72 .

Need test.


Run two instances of sample/multiplayer/multiplayer.tscn and connect them. Then continuously moving one of them, the synchronization will be broken after few seconds and push error:

E 0:00:16:0622   talo_socket.gd:75 @ send(): Condition "ready_state != STATE_OPEN" is true. Returning: FAILED
  <C++ 源文件>      modules/websocket/wsl_peer.cpp:702 @ _send()
  <栈追踪>          talo_socket.gd:75 @ send()
                 channels_api.gd:153 @ send_message()
                 talo_multiplayer_peer.gd:145 @ _send_packet_message()
                 talo_multiplayer_peer.gd:202 @ _put_packet_script()

@tudddorrr could you test this pr to find the reason about this error?

@Daylily-Zeleen Daylily-Zeleen force-pushed the daylily-zeleen/talo_multiplayer_peer branch 2 times, most recently from b2714c9 to d409c5b Compare February 26, 2025 03:55
@Daylily-Zeleen Daylily-Zeleen changed the title Add TaloMultiplayerPeer. Add TaloMultiplayerPeer and multiplayer sample. Feb 26, 2025
@tudddorrr
Copy link
Contributor

Implemented through Talo Channels.

Need #72 .

Need test.

Run two instances of sample/multiplayer/multiplayer.tscn and connect them. Then continuously moving one of them, the synchronization will be broken after few seconds and push error:

E 0:00:16:0622   talo_socket.gd:75 @ send(): Condition "ready_state != STATE_OPEN" is true. Returning: FAILED
  <C++ 源文件>      modules/websocket/wsl_peer.cpp:702 @ _send()
  <栈追踪>          talo_socket.gd:75 @ send()
                 channels_api.gd:153 @ send_message()
                 talo_multiplayer_peer.gd:145 @ _send_packet_message()
                 talo_multiplayer_peer.gd:202 @ _put_packet_script()

@tudddorrr could you test this pr to find the reason about this error?

I'll try to look at this tomorrow or over the weekend :)

@Daylily-Zeleen Daylily-Zeleen force-pushed the daylily-zeleen/talo_multiplayer_peer branch 2 times, most recently from da7c05c to 38f4ea6 Compare March 2, 2025 04:29
@tudddorrr
Copy link
Contributor

@Daylily-Zeleen looks like you're encountering rate limit errors. each socket connection is granted 100 requests per second. to get this sample working you would need to check if rate limit errors are received (RATE_LIMIT_EXCEEDED). clients are warned 3 times before being disconnected if they exceed the rate limit.

@Daylily-Zeleen
Copy link
Contributor Author

I'm not sure, I have test about this, connectd Talo.socket.message_received in TaloMultiplayerPeer.listen_channel(), and have not receive message with "v1.error", and I set the MultiplayerSynchornizer's "replication_interval" and "delta_interval" to 0.02, it should not exceed the limitation. Maybe due to my terrible network environment?

Your can adjust the MultiplayerSynchornizer's "replication_interval" and "delta_interval" in player.tscn to do some further test.

@tudddorrr
Copy link
Contributor

You're right about the v1.error message not coming through - I need to investigate why this is. However, running this locally I can see in my docker logs that the clients are being disconnected because of the rate-limiting. I haven't worked with Godot multiplayer before so unfortunately I don't know where to adjust these settings, can you point me in the right direction?

@Daylily-Zeleen
Copy link
Contributor Author

You're right about the v1.error message not coming through - I need to investigate why this is. However, running this locally I can see in my docker logs that the clients are being disconnected because of the rate-limiting. I haven't worked with Godot multiplayer before so unfortunately I don't know where to adjust these settings, can you point me in the right direction?

image

In my environment, set intervals to 0.02s (50 times per second) will broken the connection, too.

2025-03-03.14-30-03.mp4

@tudddorrr tudddorrr added the enhancement New feature or request label Mar 3, 2025
@tudddorrr
Copy link
Contributor

That was it - setting both values to 0.2 fixes it for me. These should be the default values ideally. If you try setting it to a higher value does that work? Looks like there's a few things that need to happen before the can be merged:

  1. I need to work out why the v1.error for rate limiting isn't being received. Maybe there should be a signal fired when this happens (the logging might be overflowing and therefore not printing it).
  2. The channels table needs to be updated to support BIGINTs for the messageCount column to preventing overflow errors

I still haven't had a chance to look at the full code but the sample is looking really good!

@Daylily-Zeleen
Copy link
Contributor Author

I adjust intervals to 0.03 second, the connection will become broken, too.
Maybe the rate limitation check in back end should be optimized for different network environment.

@tudddorrr
Copy link
Contributor

tudddorrr commented Mar 4, 2025

Yeah you're right - I think I can increase the rate limit so that it handles synchronisation more smoothly

@tudddorrr
Copy link
Contributor

I've bumped the rate limit now, hopefully it should work better for you?

@Daylily-Zeleen
Copy link
Contributor Author

Daylily-Zeleen commented Mar 5, 2025

I think my network environment can't use Talo. The latency is over 1 second and can be disconnected easily.

image


Maybe we need a new way to transfer message without rate limitation to implement MultiplayerPeer, at least it should support default intervals value of MultiplayerSynchronizer, It should be optimize parameters instead of limitations, and users can use multiply MultiplayerSynchronizer, the transfer rate will become 3 times, 4 times, or more...

@tudddorrr
Copy link
Contributor

By "disconnected" do you mean the clients are getting out of sync quickly? I don't think your latency would be affecting how quickly you're being rate limited given that the request count that contributes to the limit are reset every 1 second.

I think you need some interpolation to handle the movement syncing, this is a pretty common pattern in games. With that in place you can increase the intervals.

@tudddorrr
Copy link
Contributor

@Daylily-Zeleen in the latest dev branch, there's now a error_received signal on the Talo Socket, allowing you to easily check for rate limiting errors

@Daylily-Zeleen Daylily-Zeleen force-pushed the daylily-zeleen/talo_multiplayer_peer branch from 38f4ea6 to a6afe17 Compare March 24, 2025 09:29
@Daylily-Zeleen Daylily-Zeleen force-pushed the daylily-zeleen/talo_multiplayer_peer branch from a6afe17 to 65e0b8c Compare March 24, 2025 09:54
@Daylily-Zeleen Daylily-Zeleen marked this pull request as ready for review March 24, 2025 09:55
@Daylily-Zeleen
Copy link
Contributor Author

I collect messages into a queue and send them in _poll(), to ensure a peer can send only once per frame.
And I tune the sync intervals to 0.03 s, I still got error "Too Many Requests".

I think my network environment can't use Talo, it seems like the sending rate of messages is unstable, see these videos.

I will stop use Talo, but the TaloMultiplayerPeer in this pr is functionally complete, you can consider to merge.

@tudddorrr
Copy link
Contributor

Thanks @Daylily-Zeleen. I'm still not totally convinced it's anything to do with your network environment. I really appreciate all your contributions and I'll look into picking this up at some point :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants