-->

The latest recommendation for Comet in Python? [cl

2019-01-10 08:53发布

问题:

I'm going to be implementing Comet in Python (even though I hear good things about erlycomet I'm not thrilled about supporting an Erlang-based web server in addition to everything else in our back end). I've found several possibilities:

  • Diesel
  • Tornado
  • Twisted-comet
  • Orbited (uses twisted)

(there are also some other choices that interface with Java servers, but I'm not interested in those)

Can somebody make a recommendation among these implementations, considering performance, community, and ease of implementation?

回答1:

I am personally using Orbited, both because I am already using Twisted and because it seems mature. Twisted has a nice long history with many users, especially in comparison to Diesel and Tornado. Orbited is indeed built on Twisted.

There is a good blog entry covering an end-to-end orbit solution here. It sends data from a python script to a STOMP server (MorbidQ) to Orbited to Javascript - rendering that data as a graph.

Tornado seems pretty new to the scene, I couldn't find twisted-comet and I hadn't heard of diesel. I particularly like the way that Orbited can forward any sort of tcp/ip but makes it easy to hook javascript clients in with a message passing STOMP backend.



回答2:

I'd recommend Orbited if you're looking to write a Comet app.

What makes Comet more complex to implement (than making an Ajax app, say), is that you need both the client (a Comet javascript client) and the server (an asynchronous webserver like Twisted) working in conjunction, and this is what you get with Orbited - both the javascript client and the server.

Both Tornado and Diesel provide mainly the async server part, but are missing the important client javascript code.

Plus, there is a pretty good community around Orbited, and several people are building cool apps with it, this pages shows a couple of those apps: http://orbited.org/wiki/Sites



回答3:

I've also been using Twisted. But instead of Orbited, I'm using Nevow.Athena. It's really simple: learn more reading the LiveElement tutorial.



回答4:

Are you settled on Comet? Why not WebSockets? If the latter is also an option, I'd like to refer https://github.com/tavendo/AutobahnPython which implements WebSockets in Twisted (documentation is available on http://autobahn.ws/python). It is standards compliant, has message-based basic API and advanced API for frame-based/streaming processing and many more goodies.



回答5:

My answer to this question provides an example of server push using the autobahn library which IMHO is so far the most user friendly WebSocket framework powered by Twisted. Also a JS implementation is available as well as Android.

Comet is fully replaced by WebSocket and you should consider using the latter unless you plan to support IE8 and older



回答6:

try WebSocket-for-Python



回答7:

Tornado works fine you can fine a websockets example here : https://github.com/Introduction-to-Tornado/Introduction-to-Tornado/tree/master/asynchronous_web_services/websockets