master
1from random import uniform
2from geojson import Point as point
3from geojson import Feature as feature
4
5import tornado.httpserver
6import tornado.websocket
7import tornado.ioloop
8import tornado.web
9
10
11class WSHandler(tornado.websocket.WebSocketHandler):
12 def open(self):
13 print 'new connection'
14 self.write_message(point_plus_accuract())
15
16 def on_message(self, message):
17 print 'message received %s' % message
18
19 def on_close(self):
20 print 'connection closed'
21
22
23application = tornado.web.Application([
24 (r'/ws', WSHandler),
25])
26
27
28
29def point_plus_accuracy(lat=None, lon=None, accuracy=None):
30 if lat is None: lat = uniform(-180,180)
31 if lon is None: lon = uniform(-90,90)
32 if accuracy is None: accuracy = uniform(0,20000)
33 return feature(geometry=point((lat,lon)), property={'accuracy': accuracy})
34
35print [point_plus_accuracy() for x in xrange(10)]
36
37http_server = tornado.httpserver.HTTPServer(application)
38http_server.listen(8888)
39tornado.ioloop.IOLoop.instance().start()