gevent + flask + websocketで簡単なwebサーバを作成しています。
コードは下記で、ローカルホストでは接続できていました。
同一ネットワークの別PCのブラウザからアクセスするよう変更したところ
ページは表示されるものの、websocketが接続できなくなりました。
pythonコードのhostをA.B.C.Dに変更しても同様でした。
ブラウザはfirefoxで、サーバもクライアントもA.B.Cの同一ネットワーク上にあります。
別PCのブラウザからアクセスする方法をご教授ください
python
app = Flask(__name__) app.config.from_object(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/pipe') def pipe(): if request.environ.get('wsgi.websocket'): web_sock = request.environ['wsgi.websocket'] while True: hoge = web_sock.receive() somefunc(hoge) time.sleep(1) return host = '0.0.0.0' port = 5000 host_port = (host, port) server = WSGIServer( host_port, app, handler_class = WebSocketHandler ) server.serve_forever()
js
var host = "WS://A.B.C.D:5000/pipe"; var ws = new WebSocket(host); ws.onmessage = function(message){ //someprocess };
あなたの回答
tips
プレビュー