B4J Question Custom WebSocket Push Framework Reconnection Problem


Well-Known Member
Licensed User
Longtime User
Some times, it's occuring the following problem:
It is possible to have an internet line problem to my server.
The connections with the tablets, may totally be recovered but there is an option that may will be semi-recovered.
I have noticed that after a server internet disconnection, I may have communication from tablets to server, but the server cannot send anything to tablets!
Do you have any other suggestion?
Is it a good idea to implement an MQTT service?

Thank you in advance...


B4X founder
Staff member
Licensed User
Longtime User
This B4A code will close the connection from the client side if the server didn't send a "pong" message for more than 30 seconds:
Sub PingTimer_Tick
   'Log("PingTimer_Tick: " & wsh.ws.Connected & ", " & lastServerPong & ", "  & (lastServerPong + 30 * DateTime.TicksPerSecond < DateTime.Now))
   If wsh.ws.Connected = False Then Return
   If lastServerPong + 30 * DateTime.TicksPerSecond < DateTime.Now Then
     'Log("Closing connection after 30 seconds of no response")
     Dim m As Map
     wsh.SendEventToServer("Device_Ping", m)
   End If
End Sub
Once the connection is closed, a new connection will be made.
Upvote 0