I decided to keep track of multiple web socket connections. I need to save WebSocket Handler objects in a list. But I have several handlers - one for each WS URI (endpoint). Let's say my project has three end points - A, B, C
ws:
ws:
ws:
So, to handle the connections for each of them, I have three handlers. Therefore, I am puzzled by where to create a list for storing handlers that will be used later.
My code before adding a list is
class WSHandlerA(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("Hello World")
def on_message(self, message):
print 'message received %s' % message
def on_close(self):
print 'connection closed'
class WSHandlerB(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("Hello World")
def on_message(self, message):
print 'message received %s' % message
def on_close(self):
print 'connection closed'
class WSHandlerB(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("Hello World")
def on_message(self, message):
print 'message received %s' % message
def on_close(self):
print 'connection closed'
application = tornado.web.Application([
(r'/A', WSHandlerA),
(r'/B', WSHandlerB),
(r'/C', WSHandlerC),
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
So, where can I create this list and make sure that it is visible to all created objects? I am also new to python and therefore have a little problem wrapping around myself.
, URI ( ) . WebSocket . , URI, .
.