From 54f193051bf51693ab87f8b4da3dc20032e5d5a9 Mon Sep 17 00:00:00 2001 From: sidya82 Date: Thu, 27 Feb 2014 21:38:17 +0100 Subject: [PATCH] =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20supe?= =?UTF-8?q?rTornado.py=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20test.h?= =?UTF-8?q?tml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- superTornado.py | 21 ++++++++++-------- test.html | 57 +++++++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/superTornado.py b/superTornado.py index 6090b61..4c22529 100644 --- a/superTornado.py +++ b/superTornado.py @@ -47,19 +47,22 @@ class VideoHandler(tornado.web.RequestHandler): def get(self): self.render("test.html") -class WSHandler(tornado.websocket.WebSocketHandler): - def open(self): - self.callback = PeriodicCallback(self.send_hello, 120) - self.callback.start() - - def send_hello(self): - self.write_message('hello') +class WebSocketHandler(tornado.websocket.WebSocketHandler): + def open(self, *args): + self.id = self.get_argument("Id") + self.stream.set_nodelay(True) + clients[self.id] = {"id": self.id, "object": self} def on_message(self, message): - pass + """ + when we receive some message we want some message handler.. + for this example i will just print message to console + """ + print "Client %s received a message : %s" % (self.id, message) def on_close(self): - self.callback.stop() + if self.id in clients: + del clients[self.id] application = tornado.web.Application([ diff --git a/test.html b/test.html index ccdc369..d0b8b4f 100644 --- a/test.html +++ b/test.html @@ -1,30 +1,31 @@ + - - - - - - - - + + + + + + Run WebSocket +
+