WebSocket connection fails when connected through 3G on flask-sockets and gunicorn

425 views Asked by At

I've written a small app which uses WebSockets using flask-sockets. I'm currently serving the site straight from gunicorn (using the gevent worker from flask-sockets), with no nginx or anything in front, because it's just a small experiment. when trying to access the site on my smartphone while connected to an access point, the site works fine. On the other hand, when connected with 3G, the site is loaded but the websocket connection fails.

I get this in the server log:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 438, in handle_one_response
self.run_application()
File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 424, in run_application
self.result = self.application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask_sockets.py", line 37, in __call__
environment = environ['wsgi.websocket']
KeyError: 'wsgi.websocket'
<PyWSGIServer fileno=5 address=192.168.1.50:80>: Failed to handle request:
  request = GET /clock_skew HTTP/1.1 from ('80.246.130.25', 36438)
  application = <Flask 'flask_client_id.client_id'>

I thought maybe it has something to do with proxy servers in the middle messing with the web socket headers or something, so I tried to change the JS code to 'wss://' on the client side, but that doesn't work at all (no client can establish a connection).

I'll appericate anyone who can provide me with any ideas on this.

1

There are 1 answers

0
Tommaso Barbugli On

This is quite of a frequent problem with 3G operators (at least in europe).

I suggest you to try to run your webserver on a different port than 80, better if thats a port for some known service (eg. 443)