2

I am trying to use the Poco C++ lib's WebSocket class to build a nice clean interface into my server application.

My problem is that using the example WebSocket server application, the socket is closed to the client after 60 seconds - and I need it to last much longer (think +15mins...)

I have tried setting the timeout of the HTTP layer to 10 mins (3600 secs) and this make no difference to the behaviour.

Unfortunately Poco examples and docs are a little thin - so I was hoping someone here might be able to help.

justacodemonkey
  • 620
  • 1
  • 8
  • 20
  • If there is any Ping function to send to client? WebSockets protocol it self has PING and PONG OpCodes. The library might disconnect clients after some inactivity. – moka Apr 10 '12 at 14:22
  • I did think this might be the case - in which case I need to find a way to prevent that behaviour. I am planning to use the WebSocket to a mobile client - and I want to restrict traffic to a minimum to save battery life. – justacodemonkey Apr 10 '12 at 14:30
  • As well check function setKeepAlive for WebSocket in Poco. And question: are you using Browser to connect to server, or another Poco application with Poco client WebSocket? As well based on documentation, Ping and Pong has to be handled by application developer. So it is not handled by library it self. – moka Apr 10 '12 at 14:31
  • I will look at the setKeepAlive also. – justacodemonkey Apr 10 '12 at 14:32

3 Answers3

1

The timeout can be set using

ws.setReceiveTimeout(Poco::Timespan(days, hours, minutes, seconds, microseconds));

how to keep websocket connect until either-side close?

Community
  • 1
  • 1
waynix
  • 501
  • 3
  • 13
0

The timeout may be due to thread (pool) and not WebSocket itself. You may want to set a different idle time via its constructor. See http://pocoproject.org/docs/Poco.ThreadPool.html

0

The reason connection is closed is because WebSocket is created on the stack in handler. Handler is called for every request and is short-lived. To let it last longer, you should create it on the heap and keep reference to it in the factory (or some other long-lived object), so it remains alive after the HTTP request is handled.

Étienne
  • 4,773
  • 2
  • 33
  • 58
Alex
  • 5,159
  • 4
  • 25
  • 33