For i=0 To ActiveConnections.Size-1
Dim wsc As WSController
wsc = ActiveConnections.GetValueAt(i)
If wsc<>Null Then
wsc.ws.RunFunction(command, params)
wsc.ws.Flush
End If
Next
That's what i do, I use the exact code from PushB4A module:
B4X:
Private Sub WebSocket_Disconnected
If id <> "" Then CallSubDelayed3(WSShared, "RemoveConnection", id, Me)
End Sub
end
B4X:
Public Sub RemoveConnection(Id As String, pb As WSController)
If pb <> ActiveConnections.Get(Id) Then Return 'this can happen if there was a "phantom" connection
ActiveConnections.Remove(Id)
End Sub
Maybe WebSocket_Disconnected is not called for some reason, or client disconects while serverd is sendind data.
I don't know if it is related or not however it seems like you haven't created a thread safe map for ActiveConnections. This can also cause problems.
The Try / Catch solution is a good solution in this case as it is indeed possible that the connection was broken and the server doesn't yet know the correct status.