Im creating a program in Python that reads a stream of data on an unknown interval. This program also sends this data through websockets.
The program is the server and it sends the received data to the clients.
This is the code of the server now:
print 'Websocket opened'
print 'New connection'
self.write_message('Test from server')
print 'Connection closed'
if __name__ == '__main__':
application = make_app()
http_server = tornado.httpserver.HTTPServer(application)
time.sleep(10) # a while loop to simulate the reading
print 'read serial'
str = 'string to send'
# send message here to the clients
connections = set() outside the WebsocketHandler and add every client on opening a connection with
connections.add(self). Do not forget to remove them on closing with
Now, you are able to access
write_message out of the websocket thread through:
[client.write_message('#your_message') for client in connections]