How to keep alive HTTP session?

0 votes
asked Dec 18, 2018 by Lukas Matyska (55,470 points)

(This question was converted from comment)

Hi Lukas,
Very Good morning,
We are using Rebex client for - TLS12 - for Webservices over https - we are observing below scenarios:

  1. Whenever the device - Establishing the connection with Server, the Alerts which the device sent is reaching the server with in 2 to 4 seconds

  2. If we leave the Device for 1 hour idle the same alerts will take around 20 seconds.

Hence we requesting your help to understood whether is the Any Keep alive concepts is available for https/TLS12 - to keep the session created for particular server for a while,
To avoid disconnect the session after timed out and establishing with following all process like - Certificate verification, TLS12 negotiation and all?

1 Answer

0 votes
answered Dec 18, 2018 by Lukas Matyska (55,470 points)

Hello RajaK,

There is no auto keep alive functionality in Rebex HTTP. If you want to keep the connection alive, you have to send some data to the server periodically for yourself.

If I would do this for general case, I would create Noop() method on the WebService, which will just return "OK". I would call this WS method in background every 30 seconds, so the connection will never expire. I would do it with two conditions:

  1. The Noop is not performed if any other request is currently running.
  2. If Noop is currently running, new requests will wait for Noop to finish.

However, please note about consequences it will take. The 20 seconds delay is very probably caused by re-establishing the Internet connection. The device closed Internet connection "subsystem" during idle to save battery, etc. If new request was started after 1 hour of idle, the device connection manager had to establish Internet connection "subsystem" first, then new TCP/IP connections could be established. It can take observed 20 seconds.

commented Dec 20, 2018 by RajaK (110 points)
Thank You Lukas,
If we need to implement NOOP in Webservcies means server side also - WSDL chnages required.
I was checking in device whether TCP/IP is losed it connectivity  - but device is still talking with other server  - hence seems TLS12 communication only disconnected after certain amount of time.
In Idle Case  - for every Transaction  - Certificate Exchange/TLS12 negotiation required for https mode ? do we have any concepts like use existing session  untill physical connection is dropped out ? Like broken Pipe in Socket communications?
commented Dec 23, 2018 by Lukas Matyska (55,470 points)
The HTTP session is cached for later use on client side for 50 seconds. This value is currently not configurable, but in the next version, you will be able to set this value using HttpRequestCreator.Settings.HttpSessionCacheTimeout. If you want to receive beta version, please let us know. However, please note that the server has similar limit. It is couple of minutes at max, so if the device is idle for one hour, this will not help you.

Yes, every new connection requires TLS1.2 negotiation. If the server supports renegotiation, the cached session can be used to renegotiate and the whole TLS negotiation process is much faster.

Please, create communication log in  Debug level and send it to support@rebex.net for analysis. After seeing the log, I can tell you other possibilities. The log can be created like this:

creator.LogWriter = new Rebex.FileLogWriter("/http.log", Rebex.LogLevel.Debug);
commented Dec 24, 2018 by RajaK (110 points)
Thank You  Lukas,
I  willl try to collect the logs. in met time if get the Beta version with HttpRequestCreator.Settings.HttpSessionCacheTimeout included means it will be more helpfull to get more test data..
commented Dec 25, 2018 by Lukas Matyska (55,470 points)
I have sent you link to full beta version to your email.

You can set HttpRequestCreator.Settings.HttpSessionCacheTimeout to your required value (default is  50 seconds).

However, please note that even if you set the timeout to e.g. 2 hours, the connection will be dropped by the server, which typically keeps HTTP sessions only couple of minutes.
commented Dec 26, 2018 by RajaK (110 points)
Thank You Lukas,
  I have set the Timeout as 2 minutes and captured the Rebex logs and shared to support@rebex.net
...