B4J Question Websocket shutdown after too many requests?

Alexander Stolte

Expert
Licensed User
Longtime User
I am currently creating an example project for broadcasting with the supabase library. I am broadcasting my mouse movements with the project. After I have moved the mouse a lot, for about 10 seconds, the websocket no longer sends or receives anything. Is this a spam protection of the websocket or does it not cope with the fact that I send and receive many requests?

I get the following error message when I continue to move the mouse:
B4X:
2023-11-29 17:33:50.671:INFO :oejwc.WebSocketClient:pool-3-thread-4: Shutdown WebSocketClient@c388d1d6[coreClient=WebSocketCoreClient@3d6e54ea{STARTED},openSessions.size=0]

B4X:
Private Sub MouseMoved(x As Int,y As Int)
    'If x Mod 10 = 0 Or y Mod 10 = 0 Then
    Dim m As Map = CreateMap("x":X.As(String),"y":Y.As(String),"clr":MySessionColor.As(String),"usr_id":ThisUser.Id,"username":ThisUser.Metadata.Get("username"))
    If ThisChannel.IsInitialized = False Then Return
    ThisChannel.SendBroadcast("cursor-pos",m)
End Sub

Or can the whole thing be slowed down a little by not sending everything?
 
Solution
It is a mistake to implement it like this.

You should instead do something like:
B4X:
Private Sub MouseMoved(x As Int,y As Int)
 LastX = x 'global variables
 LastY = y
End Sub

Private Timer1_Tick
 'send LastX / LastY

Now play with the timer interval. And make sure to test it in release mode.

Alexander Stolte

Expert
Licensed User
Longtime User
Thank you very much, I knew it couldn't be right, but I didn't find anything anywhere that indicated this...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…