B4J Question Websocket Timeouts with Raspberry Pi Server

lip

Active Member
Licensed User
Longtime User
I have been trying to keep Websocket connections open and available between Pi Clients around the country and a central server with mixed results. I have been experimenting with three servers: A Pi with a fixed IP address on Port 80, The same Pi on port 51042 and a Microsoft Azure server on port 80 and 443.

I have been sending a very short command from the server to 'ping' each client every few seconds.

I have used the same B4J program on each sever, changing only two things (i) the Port and (ii) the number of seconds between 'pings'.

I have used a single Client Pi, just changing its Websocket URL string to reflect the change in Port.

It seems that running the same B4J program on the same Pi with two different Ports results in very different timeouts: On Port 80 it is about 60 seconds and on Port 51042 it is about 5 minutes.

Does this sound right?

Can I change the Timeout setting on the B4J Server for each Port number?

If yes - then will the same setting work on the Azure server too?
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
after your srvr is started, try adding this:

B4X:
Dim jo As JavaObject = srvr
Dim connectors() As Object = jo.GetFieldJO("server").RunMethod("getConnectors", Null)
Dim timeout As Long = SessionMaxInactiveIntervalSeconds*1000 ' <------------ change this accordingly
For Each c As JavaObject In connectors
     c.RunMethod("setIdleTimeout", Array(timeout))
Next
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The weird part is that it looks like the source for the server library sets the timeout for a Websocket to 180 minutes

AddWebSocket (https://github.com/AnywhereSoftware...resoftware/b4j/object/ServerWrapper.java#L328) sets a maxIdleTime of 180. This value is passed on to the WebSocketModule.Servlet method (https://github.com/AnywhereSoftware...resoftware/b4j/object/ServerWrapper.java#L178), where it is stored in that class' maxIdleTimeMinutes property. Which is then used to set that WebSockets setIdleTimeout policy (https://github.com/AnywhereSoftware...esoftware/b4j/object/WebSocketModule.java#L53). So I'm going to conclude that
  1. This idle timeout does not work (the Jetty server configuration does not stick, does not work).
  2. Something else on the server is shortening the timeout.
  3. The client is actually timing out, at which point you are at the mercy of the client (unless you can find a way to influence the clients timeout setting).
Unless I'm reading the code incorrectly (very likely), I'm leaning towards #3, then #2.

Oh yeah -> #4 something totally different (I'm not a guru).
 
Upvote 0
Top