我正在使用 nginx 从 9000 到 80 端口代理我的测试 websocket,并且我的所有测试都可以,直到客户端位于 web 代理之后,然后握手过程失败,问题可能出在哪里?在此先感谢您的时间。
我收到这些错误:
客户:
WebSocket connection to 'ws://myserver/ws/' failed: Error during WebSocket handshake: Unexpected response code: 502 autobahn.min.js:62
服务器:
2014-01-10 19:51:22-0300 [PubSubServer1,19,127.0.0.1] Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 586, in _doReadOrWrite
why = selectable.doRead()
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 199, in doRead
rval = self.protocol.dataReceived(data)
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/twisted/websocket.py", line 77, in dataReceived
self._dataReceived(data)
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/websocket/protocol.py", line 1270, in _dataReceived
self.consumeData()
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/websocket/protocol.py", line 1303, in consumeData
self.processHandshake()
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/websocket/protocol.py", line 2819, in processHandshake
self.sendServerStatus()
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/websocket/protocol.py", line 3276, in sendServerStatus
self.sendHtml(html)
File "/usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg/autobahn/websocket/protocol.py", line 3219, in sendHtml
response += "Content-Length: %d\x0d\x0a" % len(raw)
exceptions.NameError: global name 'raw' is not defined
我的测试服务器:
import sys
from twisted.python import log
from twisted.internet import reactor
from autobahn.twisted.websocket import listenWS
from autobahn.wamp import WampServerFactory, \
WampServerProtocol
class PubSubServer1(WampServerProtocol):
def onSessionOpen(self):
self.registerForPubSub("http://test.com/test")
if __name__ == '__main__':
log.startLogging(sys.stdout)
factory = WampServerFactory("ws://localhost:9000", debugWamp = 'debug',externalPort=80)
factory.protocol = PubSubServer1
factory.setProtocolOptions(allowHixie76 = True)
listenWS(factory)
#reactor.listenTCP(9000, factory)
reactor.run()
命令:
~$ python /home/my/wsbroker.py
/usr/local/lib/python2.7/dist-packages/zope.interface-4.0.5-py2.7-linux-x86_64.egg/zope/__init__.py:3: UserWarning: Module twisted was already imported from /usr/lib/python2.7/dist-packages/twisted/__init__.pyc, but /usr/local/lib/python2.7/dist-packages/autobahn-0.7.3-py2.7.egg is being added to sys.path
已编辑:
握手失败的调试信息(使用 Web 代理的客户端):http
://pastebin.com/aN4ppA2e
已完成握手的调试信息(没有代理的客户端): http: //pastebin.com/5rXREY2q