John Smith's Blog

Ramblings (mostly) about technical stuff

Installing pywebsocket and samples on Fedora

Posted by John Smith on

I've been playing a bit with a Python implementation of WebSockets over the past couple of days, and whilst the documentation does cover everything, it's a bit uncentralized. Here are some of my notes about getting it up and running on Fedora 11 and 12...



Support for WebSockets across all browsers is still an issue, but I've tested this successfully with the following browsers as of :

  • Firefox 4.0 nightly build (Fedora, WinXP)
  • WebKit nightly (Fedora)
  • SRWare Iron 6.0.475 (WinXP)
  • Safari 5.0.2 (WinXP)
The following however didn't work:
  • SRWare Iron 5.0.382 (WinXP)
  • Firefox 3.6.10 (WinXP)
As far as I know, WebSockets functionality works equivalently across all operating systems, but I've indicated the specific configurations I've tried just in case.

The protocol has changed over time, I believe Opera and older versions of Chrome only support an older version, which can be made to work with this library according to the documentation, but which I haven't tried personally.

As I understand it, there are no plans for WebSockets to be supported in IE9 - surprise, surprise...

Server side packages

Although the download includes a standalone server, I've only used the module within Apache.

You need mod_python (Fedora package is similarly named) for mod_pywebsocket.

The Ruby and Wakachi sample applications use MeCab, a library for Japanese language handling. The Fedora packages needed are for that are:

  • python-mecab
  • mecab
  • mecab-ipadic
  • mecab-ipadic-EUCJP


The project page is The source can be checked out from Subversion via: svn checkout pywebsocket-read-only

To build and install the library, do the following: cd pywebsocket-read-only/src python build su {enter root password} python install {exit root session}

Verify that the module has been installed within your PYTHONPATH by importing it from an interactive Python session without errors: python import mod_pywebsocket {exit python session}

For the purposes of these tests, I created a new Apache configuration file, serving on port 8003. Create a file /etc/httpd/conf.d/websocket_test.conf with the following content, modifying the highlighted directory paths as appropriate: # An Apache config for the testing the pywebsocket samples # # Put this in /etc/httpd/conf.d and restart Apache # This line should be unnecessary # PythonPath "sys.path+['/websock_lib']" <IfModule python_module> PythonOption mod_pywebsocket.handler_root /proj/3rdparty/pywebsocket/websocket-sample-read-only/python PythonHeaderParserHandler mod_pywebsocket.headerparserhandler </IfModule> Listen 8003 NameVirtualHost *:8003 <VirtualHost *:8003> DocumentRoot /proj/3rdparty/pywebsocket/websocket-sample-read-only/html Options Indexes MultiViews FollowSymLinks ServerName ErrorLog logs/pywebsocket_error.log CustomLog logs/pywebsocket_access.log common ErrorDocument 404 /error.html </VirtualHost>

Restarting Apache will pick up this new configuration.


The sample applications are a separate project located at Checking out the code can be done via svn checkout websocket-sample-read-only

The count and litechat sample applications use local files to store state.

These files need to be made writable by the account that runs Apache:

  • python/pub/litechat/messages
  • python/pub/count/count
If you don't make this permission change, then you're liable to get the browser applications closing the connection prematurely, which initially made me think it was a problem on the client side rather than the server side.

These files need to be updated to reflect the location of the aforementioned files:

  • python/pub/litechat/
  • python/pub/count/
The path defined in the 'file' variable needs changing along these lines: diff 86c86 < file = '/proj/3rdparty/pywebsocket/websocket-sample-read-only/python/pub/count/count' --- > file = '/home/komasshu/websock_handler/pub/count/count'

At this point you should hopefully be good to try the sample applications...


Shows the number of connected clients


A simple chat application where you enter a message to broadcast to the other connected clients.

ruby and wakachi

These are a bit more complicated to understand, as they assume you know something about how the Japanese language works.

Japanese is normally written without any spaces between words. The wakachi demo processes some sample text, putting spaces between the words.

Japanese also has 3 alphabets. Two of them are syllabic in nature - the symbol/ideograph directly indicates how it should be pronounced. However kanji can have multiple ways of being read. Ruby characters are kana which can be printed alongside the kanji in a smaller font to indicate the correct pronunciation. The ruby demo takes the same regular Japanese text, processing it to add these ruby characters where needed.

I should point out that I wasn't able to get the XHR functionality of these two applications to work - the Apache logs showed 404 errors. As the point of these applications is to show WebSockets in action, I didn't bother investigating what the problem was with the XHR stuff.

About this blog

This blog (mostly) covers technology and software development.

Note: I've recently ported the content from my old blog hosted on Google App Engine using some custom code I wrote, to a static site built using Pelican. I've put in place various URL manipulation rules in the webserver config to try to support the old URLs, but it's likely that I've missed some (probably meta ones related to pagination or tagging), so apologies for any 404 errors that you get served.

RSS icon, courtesy of RSS feed for this blog

About the author

I'm a software developer who's worked with a variety of platforms and technologies over the past couple of decades, but for the past 7 or so years I've focussed on web development. Whilst I've always nominally been a "full-stack" developer, I feel more attachment to the back-end side of things.

I'm a web developer for a London-based equities exchange. I've worked at organizations such as News Corporation and Google and BATS Global Markets. Projects I've been involved in have been covered in outlets such as The Guardian, The Telegraph, the Financial Times, The Register and TechCrunch.

Twitter | LinkedIn | GitHub | My CV | Mail

Popular tags

Other sites I've built or been involved with


Most of these have changed quite a bit since my involvement in them...