I have implemented a very simple websockets client to connect to a server which delivers a JSON string every minute. I have been using the following sub (based on Erel's MQTT Connect & Reconnect sub posted elsewhere) and it works fine for a few days, but once-in-a-while the application will hang and become completely unresponsive, requiring a restart.
The example application here: https://www.b4x.com/android/forum/threads/jwebsocketclient-library.40985/#content
uses a "WebSocketHandler" class to connect to the server, but I did not feel it was necessary to use a separate class just to process a simple one-way feed from the server. Somewhere in the forum I read that it was necessary to use this class but I can't understand why one cannot directly use the library functions like I have done above, especially since it does work (at least for a while). Can anyone confirm that it is necessary to use a WebSocketHandler class even for a simple application like mine?
Thanks!
B4X:
Sub ws_ConnectAndReconnect
ws.Initialize("ws")
Do While working
If ws.Connected Then ws.Close
ws.Connect(wsURL)
wait for ws_Connected
Sleep(5)
If ws.Connected Then
ws.SendText(tmsg)
Do While working And ws.Connected
Sleep(5000)
Loop
Else
Log("Cannot Connect")
End If
ws.Close
Sleep(15000)
Loop
End Sub
The example application here: https://www.b4x.com/android/forum/threads/jwebsocketclient-library.40985/#content
uses a "WebSocketHandler" class to connect to the server, but I did not feel it was necessary to use a separate class just to process a simple one-way feed from the server. Somewhere in the forum I read that it was necessary to use this class but I can't understand why one cannot directly use the library functions like I have done above, especially since it does work (at least for a while). Can anyone confirm that it is necessary to use a WebSocketHandler class even for a simple application like mine?
Thanks!