If you use web2py as a framework, you can see comet_messaging.py in gluon / contrib. It provides a function (comet_send) to receive messages from the web2py application for your clients on the network. It is based on a tornado (without SockJS support), but DistributeHandler can subclass a SockJS connection to provide backup transport support. With this approach, your clients send messages through typical GET or POST HTTP requests, which are processed using web2py controllers (or other frameworks) and receive messages from web2py controllers calling comet_messaging.comet_send (), which sends an email request to the tornado instance, which then his list of listeners explodes.
The modified lines in comet_messaging look like this: (The notification notification becomes on_open):
class DistributeHandler(sockjs.tornado.SockJSConnection): def on_open(self, r): group,token,name = [None, None, None] self.group = group or 'default' self.token = token or 'none' self.name = name or 'anonymous'
and
urls=[ (r'/', PostHandler), (r'/token', TokenHandler), (r'/realtime', DistributeHandler)]
Note: I had to remove the regex group in the DistributeHandler URL, as the sockJS tornado was choking. Still trying to figure out how to get the parameters from the path to the on_open handler.
Mslimmer
source share