Python Comet Server

Python Comet Server

I recommend you should use StreamHub Comet Server - its used by a lot of people - personally I use it with a couple of Django sites I run. You will need to write a tiny bit of Java to handle the streaming - I did this using Jython. The front-end code is some real simple Javascript a la:

StreamHub hub = new StreamHub();
hub.connect("http://myserver.com/");
hub.subscribe("newsfeed", function(sTopic, oData) { alert("new news item: " + oData.Title); });

The documentation is pretty good - I had similar problems as you trying to get started with the sparse docs of Cometd et al. For a start I'd read Getting Started With Comet and StreamHub, download and see how some of the examples work and reference the API docs if you need to:

  • Javascript API JSDoc
  • Streaming from Java Javadoc

How to implement Comet server side with Python?

First of all, I'm not async expert at all, I just investigated the topic once.
IMHO if you're using XAMPP then you're loosing the posibility of doing long polling because Apache uses thread/processes (depending on configuration) for each request.

What you need, is non-blocking web server, like Tornado, that allows splitting requests into two parts, of which the second one is fired on some event, but meanwhile server can accept subsequent inbound requests.

Example from Tornado documentation /license/:

class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
http = tornado.httpclient.AsyncHTTPClient()
http.fetch("http://friendfeed-api.com/v2/feed/bret",
callback=self.async_callback(self.on_response))

def on_response(self, response):
if response.error: raise tornado.web.HTTPError(500)
json = tornado.escape.json_decode(response.body)
self.write("Fetched " + str(len(json["entries"])) + " entries "
"from the FriendFeed API")
self.finish()

-- as far as I know this is not possible under Apache - in which fetch is regular part of request handler, which of course block until it's complete - so what you end with is frozen thread or process.

Another famous library for doing non-blocking services in Python is Twisted, but I don't know much about it, only that it also is able to help you in handling a lot of connections with only one thread/process.

Choosing and deploying a comet server

I would recommend looking into Twisted, their twisted.web server, and the comet work done on top of it at Divmod. They can handle far more concurrent connections than traditional thread or process based servers, which is exactly what you need for something like this. And, yes, I've architected systems using Twisted for COMET stuff, while using other things for the more front-facing web applications beside it. It works out well with each part doing what it does best.

What are some modern Comet servers written in Python?

It seems that for now the best option is to use Socket.io, which offer simple and feature-rich programming interface both on server and client side. The python options are:

  • gevent-socketio
  • SocketTornad.IO
  • socketIO-client

how to implement a comet server by tornado?

See tornadio2 project, which implements socket.io support for tornado.

Building a comet server from twisted.web, for a twisted.web site

You can use Orbited (which is a comet server based on Twisted) and run it in the same process as your web server. It's pretty slick. Instead of using its built-in proxy, you just use its guts directly. You'd do something like:

from orbited.cometsession import Port
...
reactor.listenWith(Port, factory=someFactoryYouWrote, resource=someResourceYouWrote, childName='tcp')

Implement Comet / Server push in Google App Engine in Python

We just announced the Channel API to do comet push with App Engine apps: http://googleappengine.blogspot.com/2010/05/app-engine-at-google-io-2010.html

If you're at Google IO, I'll be talking about this at 1pm tomorrow (on the APIs track): http://code.google.com/events/io/2010/sessions/building-real-time-apps-app-engine-feed-api.html

Here's the YouTube video of the session: http://www.youtube.com/watch?v=oMXe-xK0BWA

Hopefully last update! This is now released: code.google.com/appengine/docs/python/channel

Scala or Python to Build a Comet server to support a PHP application?

Why not node.js? It has a proven reputation of the solution that perfectly handles COMET. Everyone knows Plurk success story - one of the most popular social networking sites in Asia that has 500+mln subscribers, with up to 200k of them working in a parallel (using COMET long-polling connections). node.js memory usage is way better (~10 times less) compared to solutions based on java app server suitable for COMET (Jetty/Netty).



If you finally want to go with Java/Scala, you should first of all have a look at Atmosphere framework. It has the richest feature-set these days (supports all kinds of COMET strategies + web-sockets + servlets 3.0); out-of-the-box REST-support, based on Jersey (implementation of JAX-RS specification); integration with Akka (very powerful implementation of actors, fault-tolerance, STM, remotings etc on Scala).



Choosing a Lift, you'd probably have to re-write your application entirely, though it has a very good COMET support.

Python + comet + web (chat) - I need working(!) library/server

Have a look at Tornado a simple non-blocking webserver written in Python by the facebook team.

The comet behavior can be done with tornadio which makes possible to use socket.io javascript lib with tornado.

There is a chat example in tornadio that may look like what you are looking for. I 've tested it successfully with IE6, Firefox, Chrome and Opera.

I hope it helps



Related Topics



Leave a reply



Submit