B4J Question jServer - websocket disconnected

LucaMs

Expert
Licensed User
Longtime User
B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
   ws = WebSocket1
   tmr.Initialize("tmr", 1000)
   tmr.Enabled = True
End Sub

Sub tmr_Tick
   ws.RunFunction("NOP", Null)
   ws.Flush
   Log("tick")
End Sub

Did you try it? Just add the timer in the server and run it. It worked properly here.
Most likely I did not understand the purpose of that code :(.

I think that evey second the server tries to call a non-existing routine on the client but this fact does not raise an exception, since the websocket "seems" to be connected, so nothing should happen.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I tried exactly that code.

Log:

2017-05-15 12:53:55.544:INFO:eek:ejs.Server:main: Started @1478ms
Update DuckDNS: OK
tick
tick
tick
tick
tick
tick
tick
' <--- here (probably) I turned off the client wifi
tick
tick
tick
tick
tick



?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Let it try to run for a few minutes and see whether it detects the disconnection.

If you need to have better control over the connection state then you will need to let the client reply and check the last reply time in the timer tick event. If more than 10 seconds passed then close the connection.
 
Upvote 0
Top