This is how I've installed mod_pywebsocket
as apache extension
root@senior:/var/www# wget http://pywebsocket.googlecode.com/files/mod_pywebsocket-0.7.8.tar.gz
root@senior:/var/www# tar xvf mod_pywebsocket-0.7.8.tar.gz
root@senior:/var/www# cd pywebsocket-0.7.8/src/
root@senior:/var/www/pywebsocket-0.7.8/src# py:/./setpuup.py build
running build
running build_py
root@senior:/var/www/pywebsocket-0.7.8/src# python ./setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.6/dist-packages/mod_pywebsocket-0.7.8.egg-info
Writing /usr/local/lib/python2.6/dist-packages/mod_pywebsocket-0.7.8.egg-info
root@senior:/var/www/pywebsocket-0.7.8/src# mkdir /var/www/_wsh/
root@senior:/var/www/pywebsocket-0.7.8/src# cp example/* /var/www/_wsh/
root@senior:/var/www/pywebsocket-0.7.8/src# cd /var/www/_wsh/
root@senior:/var/www/_wsh# chmod a+x *.py
root@senior:/usr/local/lib/python2.6/dist-packages/mod_pywebsocket# cd /usr/local/lib/python2.6/dist-packages/mod_pywebsocket
root@senior:/usr/local/lib/python2.6/dist-packages/mod_pywebsocket# chmod a+rx *.py
Here is mine text inserted in httpd.conf
<IfModule python_module>
PythonPath "sys.path+['/usr/local/lib/python2.6/dist-packages']"
PythonOption mod_pywebsocket.handler_root /var/www/_wsh/
PythonOption mod_pywebsocket.handler_scan /var/www/_wsh/
#PythonOption mod_pywebsocket.allow_draft75 On
#<Location /var/www/_vsh>
# PythonHeaderParserHandler mod_pywebsocket.headerparserhandler
#</Location>
</IfModule>
After apaceh restart, I'm trying console.html
code from examples of pywebsocket directory (copied in /var/www/_wsh). But it doesnt work, I cant open the connection.
When I try to run example I got this
root@senior:/usr# /var/www/_wsh/echo_client.py
Traceback (most recent call last):
File "/var/www/_wsh/echo_client.py", line 995, in <module>
main()
File "/var/www/_wsh/echo_client.py", line 991, in main
EchoClient(options).run()
File "/var/www/_wsh/echo_client.py", line 840, in run
self._handshake.handshake()
File "/var/www/_wsh/echo_client.py", line 385, in handshake
'Expected HTTP status code 101 but found %r' % status_code)
__main__.ClientHandshakeError: Expected HTTP status code 101 but found '200'
Could you please help me find out where is the problem? Thank you
After reading many tutorials on how to set up pywebsockets
, I've ended up with this configuration:
LogLevel debug
<IfModule python_module>
Timeout 0
#This is path where I have copied pywebsocket
PythonPath "sys.path+['/usr/local/lib/python2.6/dist-packages']"
#This is path where I have my websocket connection handlers (files that responds to requests, I have there example files copied too)
PythonOption mod_pywebsocket.handler_root /var/www/websockets/
PythonOption mod_pywebsocket.handler_scan /var/www/websockets/
PythonHeaderParserHandler mod_pywebsocket.headerparserhandler
</IfModule>
Here is list of this paths for better understanding of where is what:
root@senior:/var/www/websockets# ls /usr/local/lib/python2.6/dist-packages/
mod_pywebsocket mod_pywebsocket-0.7.8.egg-info
root@senior:/var/www/websockets# ls /usr/local/lib/python2.6/dist-packages/mod_pywebsocket
common.py handshake __init__.pyc mux.pyc _stream_hixie75.pyc util.pyc
common.pyc headerparserhandler.py memorizingfile.py standalone.py _stream_hybi.py
dispatch.py headerparserhandler.pyc memorizingfile.pyc standalone.pyc _stream_hybi.pyc
dispatch.pyc http_header_util.py msgutil.py _stream_base.py stream.py
extensions.py http_header_util.pyc msgutil.pyc _stream_base.pyc stream.pyc
extensions.pyc __init__.py mux.py _stream_hixie75.py util.py
root@senior:/var/www/websockets#
root@senior:/var/www/websockets# ls .
bench_wsh.py console.html echo_wsh.py origin_check_wsh.py
close_wsh.py echo_client.py handler_map.txt pywebsocket.conf
I also had to edit mod_reqtimeout of apache to keep connection alive (see this question for more info Why would a websocket created with pywebsocket be closed automatically? )