If I start a server python wsserver.py
and then run python wsclient.py --host localhost --port 8888
the tornado server and client behave as expected.
However, if I start up a proxy server as well: node node_modules/http-proxy/bin/node-http-proxy --port 8889 --host localhost --target localhost:8888
then python wsclient.py --host localhost --port 8889
does connect, but no messages get passed.
This works fine on Max osx however fails on ubuntu and 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()
How do I debug this?
versions:
- node: 0.9.9
- http-proxy; 0.10.2
- python: 2.7
- tornado: 2.4.1