2

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

Buksy
  • 11,571
  • 9
  • 62
  • 69

2 Answers2

1

It is much easier to run it as standalone server. Have you tried that?

"""Standalone WebSocket server.

Use this file to launch pywebsocket without Apache HTTP Server.


BASIC USAGE

Go to the src directory and run

  $ python mod_pywebsocket/standalone.py [-p <ws_port>]
                                         [-w <websock_handlers>]
                                         [-d <document_root>]

<ws_port> is the port number to use for ws:// connection.

<document_root> is the path to the root directory of HTML files.

<websock_handlers> is the path to the root directory of WebSocket handlers.
If not specified, <document_root> will be used. See __init__.py (or
run $ pydoc mod_pywebsocket) for how to write WebSocket handlers.

For more detail and other options, run

  $ python mod_pywebsocket/standalone.py --help

or see _build_option_parser method below.

For trouble shooting, adding "--log_level debug" might help you.

Update

Try this link for fixing your issue.

ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
  • Yes I've tried, but I cant open another port so I want to run websockets as apache plugin – Buksy Feb 20 '13 at 19:37
  • I guess thats the link I have started all the configuration with (even before posting a question). When I compare my former config with actual, they differ only in `PythonHeaderParserHandler mod_pywebsocket.headerparserhandler`. I've just had it wrongly set. Standalone version runs without any problem, but as I've written, I didnt want to use another port – Buksy Feb 21 '13 at 10:36
1

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? )

Community
  • 1
  • 1
Buksy
  • 11,571
  • 9
  • 62
  • 69