installing punjab xmpp http client interface on ubuntu-server

Written by: daniel

Date March 23, 2009

Punjab allows to connect to an xmpp server like ejabberd, from a client that supports http requests only (for ex. javascript / ajax). It uses some clever parallel connections to handle input and output streams, so there is very little latency when sending and receiving messages.

First, install needed libraries:

apt-get install python python-twisted

then, download the source code from http://code.stanziq.com/cgit/punjab/punjab/

Once unpacked, edit the configuration file punjab.tac.
I changed the port on which punjab is running to 5821, as the default 5280 is already used by ejabberd web admin interface.

Then, install it and run:
python setup.py install
twistd -y punjab.tac

if it works, you should be able to access http://yourdomain.com:5281 (if you changed the port)

The last thing you need to configure is to setup your apache server, so you can use punjab in your sites.
As by default, you cannot open ajax connections to domains and ports different to the ones that your site uses, so we will have to use mod_proxy and mod_rewrite to enable access to punjab.

edit /etc/apache2/httpd.conf and add the following
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

edit your vhost file and add these lines:
RewriteEngine On
RewriteRule ^/http-bind/ http://yourpunjabserver.com:5281/xmpp-httpbind/ [P]

this means, that everytime you will access yourapplication.com/http-bind/, the request will be transparently proxied to http://yourpunjabserver.com:5281/xmpp-httpbind/

now add the required modules and restart apache:
a2enmod rewrite
a2enmod proxy
a2enmod proxy_http
/etc/init.d/apache2 restart

that’s it! you can now use for example the Strophe xmpp library to create your xmpp applications with javascript.

7 Responses to “installing punjab xmpp http client interface on ubuntu-server”

  1. George Morgan said:

    When you talk about the “vhost file” are you referring to the .htaccess file in the root of portion of your site using XMPP?

  2. daniel said:

    no, I mean when you configure your virtual host in apache you would put it inside “VirtualHost” tag. however, I have not tested it in .htaccess, it might work too.

  3. Problems with punjab in a local network | DevAyd Blog said:

    [...] had to change a little bit the apache proxy module configuration and it worked [...]

  4. victor said:

    hi, maybe you known howto configure punjab to write only error message to log? or disable it at all?

  5. yi said:

    Hi Daniel:

    I set up the punjab bosh server successfully. but when using strophe to send request to punjab, how could I tell punjab where my xmpp server is located and then build up connection from punjab to xmpp server??

  6. Stella said:

    Hi,

    Thanks for a great blog post and detailed explaination.

    I have Punjab installed on my web server (Ubuntu + apache). However, when I launch the page http://mydomain.com:5280/http-bind, I do not get response. Instead, I got the following error msg :

    ” Network Error (tcp_error)
    communication error occurred: Operation timed out The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again
    at a later time.”

    The twisted.log does not say very much:
    2011-08-12 10:02:33+0200 [-] Log opened.
    2011-08-12 10:02:33+0200 [-] twistd 10.2.0 (/usr/bin/python 2.7.1)
    starting up.
    2011-08-12 10:02:33+0200 [-] reactor class:
    twisted.internet.selectreactor.SelectReactor.
    2011-08-12 10:02:33+0200 [-] twisted.web.server.Site starting on 5280
    2011-08-12 10:02:33+0200 [-] Starting factory

    The important settings in the punjab.tac file is:
    root.putChild(’http-bind’, resource.IResource(bosh))
    site = server.Site(root)
    application = service.Application(”punjab”)
    internet.TCPServer(5280, site).setServiceParent(application)

    My web server is up and runing. For example, if I launch http://mydomain.com/index.html, the web page is loaded. However, http://mydomain.com:5280/http-bind does not give response.

    My questions are:
    1. In your blog, after test it by loading http://yourdomain.com:prot, you continue to configure apache server? What is the reason of doing this config? Is it because your punjab server and apache server are not located on the same machine?

    2. Is there any configuration that I have missed? In my case, the apache server and punjab are installed on the same ubuntu PC. Do I need to configure anything? If yes,how?

    Look forward your kind help!

    /Stella

    /Stella

  7. daniel said:

    Please note you need to configure a proxy and a rewrite rule on your apache server in order to get this working.
    First you may try connecting directly to punjab from the browser and checking if it works.

    best, dan

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>