如果我启动服务器python wsserver.py
,然后运行python wsclient.py --host localhost --port 8888
,龙卷风服务器和客户端按预期运行。
但是,如果我也启动代理服务器:node node_modules/http-proxy/bin/node-http-proxy --port 8889 --host localhost --target localhost:8888
然后python wsclient.py --host localhost --port 8889
连接,但没有消息传递。
这在Max osx上工作得很好,但是在ubuntu和centos上就失败了。
wsserver.py:
import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
print "opened a new websocket"
listeners.append(self)
print listeners
def on_message(self, message):
self.write_message(u"You Said: " + message)
print ("in on_message " + message)
def on_close(self):
print 'connection closed'
listeners.remove(self)
def main():
application = tornado.web.Application([(r'/ws', WSHandler)])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
wsclient.py:
# must pip install websocket-client first
from argparse import ArgumentParser
def main():
parser = ArgumentParser()
parser.add_argument('--port', type=int, required=True)
parser.add_argument('--host', required=True)
args = parser.parse_args()
from websocket import create_connection
ws = create_connection("ws://%s:%s/ws" %(args.host, args.port))
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
print "Reeiving..."
result = ws.recv()
print "Received '%s'" % result
ws.close()
if __name__ == '__main__':
main()
我如何调试这个?
版本:
- 节点:0.9.9
- http代理;0.10.2
- python: 2.7
- 龙卷风:2.4.1
你可以在节点v0.6上尝试一下吗?x请?据我所知,node-http-proxy有一些报头问题与websockets,因为从来没有节点版本(不确定与哪个版本开始)。