1
votes

I currently have a one-page Bottle project working through localhost:8080.

For the purposes of this question, assume that single page is naught but a basic short-polling chat, retrieving chatline objects from Python that contain only the sender's name and the body of the message.

Those chatline objects are stored in chat objects, with the project allowing multiple chats.

The chat and sender is determined by the URL. For example, if a chatline is sent from localhost:8080/chat/23/50, it is sent to chat 23 as sender 50, and localhost:8080/chat/23/* will display all chatlines of chat 23 in a basic overflow:auto div.

The current short-polling AJAX requests data from Python once every second. I want to make things more real-time and have decided to go with long-polling (although if you love HTML5 WebSockets, I wouldn't mind learning about them too).

My question is in two parts:

  1. How would I go about implementing a long-poll approach in such a chat system, preferably while still using Python's Bottle module?
  2. How would I then deliver the project through an actual server, accessible externally (i.e., not only from localhost)? Even making it available through LAN would be good.

I'm aware that long-polling can cause severe performance issues with servers such as Apache and would appreciate it if that fact could be factored into any answers; I'd like as scalable a solution as possible.

Any help is appreciated!

2
Have you considered using an XMPP server & BOSH as a solution?Kemal Fadillah
No, but thanks for the suggestion, I'll look into it! Would still like an answer to this question though :)Djentleman
That looks pretty useful. How well do WSGI servers handle WebSockets? Or more specifically, gevent's WSGIServer? I know geventwebsocket is meant to work with gevent.pywsgi but how scalable is such a solution?Djentleman
I'm choosing an answer, but willing to change it if any more in-depth answers are provided.Djentleman

2 Answers

1
votes

I didn't try myself but I think you can use bottle together works with Tornado http://www.tornadoweb.org/ (see Tornado - mount Bottle app).

It is possible to make long-polling with Tornado. Look at the tornadio project https://github.com/mrjoes/tornadio.

You may also be interested in http://pypi.python.org/pypi/bottle-tornado-websocket. I never used this one but it looks like the thing you are looking for.

Tornado doc has a section about running in production : http://www.tornadoweb.org/documentation/overview.html#running-tornado-in-production

I hope it helps

2
votes

I recently attended a presentation about a real-time client-server application that made great use of gevent on the Python/server side and socket.io on the client side. The speaker, Alexandre Bourget, released a gevent-socketio module ongithub, that can be used to make all the plumbing easier.

Everything worked with HTTP long polling only (but socket.io contains all the logic to switch to HTML5 WebSocket or Flash socket). Although the framework was Pyramid, I believe it should work with Bottle too!