dqpi
Posts: 33
Joined: Fri May 24, 2013 12:22 pm

tornado send

Mon Feb 17, 2014 4:43 pm

I found this sourcecode online for connecting with a webpage.

http://niltoid.com/blog/raspberry-pi-arduino-tornado/

That works fine but I have a while loop running in another file that outputs values. I want to send these values to the webpage (self.write_message). So my question is: I want to call the write_message from another file. I am not advanced in Python. How can I do this?


import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket

from tornado.options import define, options
define("port", default=8080, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')

class WebSocketHandler(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("connected")

def on_message(self, message):
print 'message received %s' % message
self.write_message('message received %s' % message)

def writemessage():
self.write_message('test')

def on_close(self):
print 'connection closed'

if __name__ == "__main__":
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[
(r"/", IndexHandler),
(r"/ws", WebSocketHandler)
]
)
httpServer = tornado.httpserver.HTTPServer(app)
httpServer.listen(options.port)
print "Listening on port:", options.port
tornado.ioloop.IOLoop.instance().start()

Feej
Posts: 8
Joined: Sun May 27, 2012 11:10 am

Re: tornado send

Sun Mar 09, 2014 1:54 pm

When you say you have a while loop running another file, what exactly does that mean? In another Python application?

Return to “Python”