2

这就是我mod_pywebsocket作为 apache 扩展安装的方式

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

这是我在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>

在 apaceh 重新启动后,我正在尝试console.html来自 pywebsocket 目录示例的代码(复制到 /var/www/_wsh 中)。但它不起作用,我无法打开连接。

当我尝试运行示例时,我得到了这个

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'

你能帮我找出问题在哪里吗?谢谢

4

2 回答 2

1

将它作为独立服务器运行要容易得多。你试过吗?

"""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.

更新

试试这个链接来解决你的问题。

于 2012-12-19T17:54:23.940 回答
1

在阅读了许多关于如何设置的教程后pywebsockets,我最终得到了这个配置:

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>

以下是此路径的列表,以便更好地了解在哪里是什么:

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

我还必须编辑apache 的mod_reqtimeout以保持连接活动(有关更多信息,请参阅此问题为什么会自动关闭使用 pywebsocket 创建的 websocket?

于 2013-02-20T20:44:59.817 回答