Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tornado.websocket
- import tornado.ioloop
- from time import sleep
- line = 0 #the current message to be send
- listeners = [] #for holding the connecting
- class WebSocketHandler(tornado.websocket.WebSocketHandler):
- def open(self):
- listeners.append(self)#add to list of connections
- def on_close(self):
- listeners.remove(self)#remove from list of connections
- application = tornado.web.Application([
- (r"/websocket", WebSocketHandler),
- ])
- def main():
- global line
- #line=ser.readline() #get the message from the serial
- print(listeners) # <-- for debugging connections
- line = line + 1
- sleep(0.01)
- for i in range(0, len(listeners)): #go trough all connections and send the new message
- listeners[i].write_message(str(line))
- if __name__ == "__main__":
- application.listen(8888)
- while(1):
- tornado.ioloop.IOLoop.instance().add_callback(main)
Advertisement
Add Comment
Please, Sign In to add comment