##// END OF EJS Templates
send ping every 30 seconds to keep websockets alive
MinRK -
Show More
@@ -17,6 +17,7 except ImportError:
17 17 import logging
18 18
19 19 import tornado
20 from tornado import ioloop
20 21 from tornado import web
21 22 from tornado import websocket
22 23
@@ -103,8 +104,12 class ZMQStreamHandler(websocket.WebSocketHandler):
103 104 """
104 105 return True
105 106
107 # ping interval for keeping websockets alive (30 seconds)
108 WS_PING_INTERVAL = 30000
106 109
107 110 class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):
111 ping_callback = None
112
108 113 def set_default_headers(self):
109 114 """Undo the set_default_headers in IPythonHandler
110 115
@@ -124,6 +129,16 class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):
124 129 self.session = Session(config=self.config)
125 130 self.save_on_message = self.on_message
126 131 self.on_message = self.on_first_message
132 self.ping_callback = ioloop.PeriodicCallback(self.send_ping, WS_PING_INTERVAL)
133 self.ping_callback.start()
134
135 def send_ping(self):
136 """send a ping to keep the websocket alive"""
137 if self.stream.closed() and self.ping_callback is not None:
138 self.ping_callback.stop()
139 return
140
141 self.ping(b'')
127 142
128 143 def _inject_cookie_message(self, msg):
129 144 """Inject the first message, which is the document cookie,
General Comments 0
You need to be logged in to leave comments. Login now