RTC Forums
November 23, 2024, 07:31:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: WebSocket Timeout  (Read 4777 times)
usernametaken
RTC Expired
*
Posts: 6


« on: June 27, 2017, 03:29:12 AM »

Maybe I don't understand everything in the SDK yet...

I have a Timeout.AfterConnecting := 60 set on my TrtcHTTPServer component.
I do this to minimize the resources used by the system.

My HTTPServer serves web pages and WebSockets.
The normal HTTP request connections TimeOut after 60 seconds as expected.

The problem is that the WebSocket connections also TimeOut after 60 seconds.

 
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: June 27, 2017, 06:18:49 AM »

Timeouts are per connection. When a Timeout is set to 60 seconds and there is no data being sent or received through that connection for 60 seconds, a Timeout is triggerd to close the inactive connection.

If you want to completely disable Timeouts after a specific event, you can change the Timeout property for that event by setting its value to -1, or change the timeout interval by using another value. For example, if you wanted to use a 300 seconds timeout after accepting and upgrading a WebSocket connection, you could set ...

 Sender.Timeout.AfterDataSent:=300;

... directly from the event where you have upgraded the connection to a WebSocket. This would change the timeout interval to 300 seconds (5 minutes) after sending the WebSocket upgrade response to the Client. Naturally, this only works if all other Timeout properties (which could trigger for the same connection afterwards) are set to 0 (default).

You could also change the timeout interval from RTC events by using the Sender.Timeout.Enable() method (check method description for details), or temporarily disable the Timeout until the next event is triggered by using the Sender.Timeout.Disable method, but ... please keep in mind that both of these methods are only temporary and will be overriden if any other event with a timeout option is triggered.

NOTE: Disabling a timeout or using very long timeout intervals does NOT give you a guarantee that a connection would NOT be closed after some time of inactivity. Especially if the Client is behind a proxy, your connections are likely to be closed if there is no data being sent or received for a while. How long a connection would stay open without any traffic depends on proxy servers and the network being used, but I wouldn't expect any connection without traffic to remain open for much loner than 30 seconds. When using WebSockets, you can send a PING frame periodically to keep your connection active. Sending a PING every 30 seconds to keep a connection active and using a 60 second timeout should work in most networks, without generating too much "noise".

Best Regards,
Danijel Tkalcec
Logged
usernametaken
RTC Expired
*
Posts: 6


« Reply #2 on: June 27, 2017, 10:41:13 AM »

Thank you for your quick and detailed explanation
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.025 seconds with 17 queries.