Bug? jServer - websocket disconnected event doesn't fire

Status
Not open for further replies.

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested your project. This is the output:

Waiting for debugger to connect...
Program started.
2017-05-12 08:08:14.755:INFO::main: Logging initialized @584ms
2017-05-12 08:08:14.823:INFO:eek:ejs.Server:main: jetty-9.3.z-SNAPSHOT
2017-05-12 08:08:14.890:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@5ebec15{/,file:///C:/Users/H/Downloads/tbookDemo/SERVER/Objects/www,AVAILABLE}
2017-05-12 08:08:14.892:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened C:\Users\H\Downloads\tbookDemo\SERVER\Objects\logs\b4j-2017_05_12.request.log
2017-05-12 08:08:15.087:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@4c83e535{HTTP/1.1,[http/1.1]}{0.0.0.0:51042}
2017-05-12 08:08:15.087:INFO:eek:ejs.Server:main: Started @918ms
Emulated network latency: 100ms
RemoteIP: 192.168.0.7
WebSocket_Disconnected
RemoteIP: 192.168.0.7
WebSocket_Disconnected
RemoteIP: 192.168.0.7
WebSocket_Disconnected
RemoteIP: 192.168.0.7
WebSocket_Disconnected


My guess is that something on your network causes it to think that it is still connected. It will probably be disconnected eventually.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I was able to reproduce it by turning off Wifi. The idle timeout is set to 3 hours. So the client will eventually disconnect.

You can add this code to help it find that there is no connection:
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
 

LucaMs

Expert
Licensed User
Longtime User
Thank you, Erel.

Using your code I should add another timer (as you know I asked if there are problems in using many timers...).

Also, one of the useful characteristics of websocket is that there is no need (for client) to poll constantly the connection but with that workaround this feature is (almost) lost (almost, because the code is server code).

For the moment I'm glad that my LAN is not the problem (in this case :().
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I was talking about the fact that you add a timer for each connection.

Every second the server will try to send a msg to each client!
There are many messages being sent by the client and the server. It is unlikely that this will have any effect on the server performance. You can also change the timer to run every 10 seconds or more. It shouldn't really matter.

I recommend you to focus on getting the solution to work. It will not be slow because of a "ping" request.
I do not understand what happens when the server is unable to "run" the "NOP" routine on clients.
Nothing will happen. The CallSub will do nothing because there is no matching sub.

Anyway, for further discussion please start a new thread in the questions forum.
 

LucaMs

Expert
Licensed User
Longtime User
for further discussion please start a new thread in the questions forum
This is not a question ;):

The workaround Erel suggested, if I understand well, is not enough.

The timer (tmr in that example) should "run" a client routine but:

1) that routine should exist on client (with a name like "SrvPing")
2) the client should respond, calling a server routine (like "CltPong")
3) another timer is needed, to wait for the "client pong"; when this time is expired we can consider the client disconnected.

All this only because the Disconnected event does not fire :( (more exactly, the server websocket does not result disconnected).
 
Status
Not open for further replies.
Top