Right now I'm reading the server side source code of "
Custom WebSocket Based Push Framework" (
here the source code).
The project uses a map to stores all "connections" (note that it does not stores websocket objects but websocket handler objects).
When a "websocket handler instance"'s websocket disconnects (WebSocket_Disconnected) a public routine of a code module will be called:
Private Sub WebSocket_Disconnected
If id <> "" Then CallSubDelayed3(PushShared, "RemoveConnection", id, Me)
End Sub
id is an identifier ("property") of the websocket handler instance; so, to "RemoveConnection", the instance and the "instance id" will be passed.
Here the (at least) strange code of "RemoveConnection":
Public Sub RemoveConnection(Id As String, pb As PushB4A)
If pb <> ActiveConnections.Get(Id) Then Return 'this can happen if there was a "phantom" connection
ActiveConnections.Get(Id) should return the PushB4A object stored (PushB4A is an instance of the websocket handler class) but...
'this can happen if there was a "phantom" connection
It's not so clear, for me, but I fear it is related rightly to my question: where websocket handler instances are stored and how to destroy them.
Note that RemoveConnection only removes the websocket handler instance (PushB4A object) from a map, which does not contain the object but a reference to it.
Well, if a hacker will try to access your B4J websocket server thousands or millions of times in a short time, your server will create thousands or millions of objects on your server.
For this reason, probably, because you can not destroy websocket handler objects, this happened:
The online example is currently disabled due to spam
(you can read the above phrase at the top of the tutorial)
You could check the user's IP address and if it is repeated too many times in a short time, you... should destroy the PushB4A objects, not just close the websocket connection.
P.S. that "id" should be the user device id; probably for this reason there can be a "phantom" connection.