B4J Question Websocket Connect

lip

Active Member
Licensed User
Longtime User
I have hundreds of Raspberry Pi's connecting to a central Rapsberry Pi server, all running B4J.

The server is based on the Server Example code but with much modification.

On the server, I am getting multiple WebSocket_Connected events called from the same session. This is not happening all the time but at least one-in-ten connection attempts do this:-

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
ws = WebSocket1
LogWithTime("Session (" & ws.Session.Id & ") Connected")
end sub

Logs
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected
12:21:30 Session (node0xnk84gn8nnftx8zwroxs16467105) Connected

Once connected, the devices run a function IdentifyOnServer command so that the websocket instance on the server can be identified by a unique identifier, however, I am getting hundreds of websocket sessions which never get the IdentifyOnServer command, presumably as the connection gets replaced by a duplicated connection. I don't seem to be able to destroy these instances in the Server. I have tried ws.close and ws.session.invalidate but the unidentified instances seem to remain active.

I would look at the log of the Raspberry pi client concerned, but I cannot identify it from the the SessionID.

Question 1: Is it possible to set an attribute in the client BEFORE I call ws.Connect on the client, so that every every Websocket_Connected event on the server can be associated with a particular client?

Possibly related: I have been putting the Sessions IDs into a map on the server, and I can see that within a minute or two of starting the server I am getting 2000+ unique SessionIDs from 500 Clients.

Question 2: Can each client connect with mutiple SessionsIDs at the same time? Or does this mean that they are losing the connection then reconnecting with a new SessionID? Or is the SessionID created by the Server?
 

lip

Active Member
Licensed User
Longtime User
When the Client Connects, I don't seem to get the option to send any ID:-

Public Sub Connect(Url As String)
ws.Connect(Url)
End Sub
 
Upvote 0
Top