title: Flask-SocketIO app keeps using polling
body: <p>I have a basic websocket server app written in<code>Flask-SocketIO</code>, sitting behind NGINX in AWS. I can successfully connect to it using a web client (both Chrome and FFox) but it keeps using polling rather than web sockets. When testing I see messages like the below in the console over and over:</p>
  
  <p>127.0.0.1 - - [2018-04-27 11:59:43] "GET /socket.io/?token=1234567890qwertyuiop&amp;EIO=3&amp;transport=polling&amp;t=1524830363623-23&amp;sid=c406e264e3ac4a06b22a1b0d4f08cf5d HTTP/1.1" 200 191 25.966415</p>
  
  <p>After some research, I added "rememberTransport: false" to the client connection options but that hasn't helped, so presumably it is something wrong with my code or config. I am hoping someone might be able to spot an obvious (noob) error I have made.</p>
  
  <h2>Update 29/4/2018</h2>
  
  <p>I altered my AWS security group so I could bypass NGINX and access the test WSGI server direct. So now I am using <a href="http://serverIP:5000" rel="nofollow noreferrer">http://serverIP:5000</a> from my local PC. I am still getting the same issue, so it cant be anything to do with the NGINX config.</p>
  
  <p>I just copied the sample code to my RPi3B and ran the server there. My Samsung phone browser, PC FFox, PC Chrome and RPi Chromium all result in a polling connection. So it looks like it is the Flask-SocketIO server that is the problem. My code is as simple as it can be so what can be wrong?</p>
  
  <p>My server code is as follows: </p>
  
  <pre><code>#!/usr/bin/env python
  from flask_socketio import SocketIO, join_room, send, emit, disconnect
  from flask import Flask, render_template, request
  
  robotAIapp = Flask(__name__)
  socketio = SocketIO(robotAIapp)
  
  @robotAIapp.route('/wsLogin.html')
  def wsLogin():
      return render_template('wsLogin.html')
  
  @socketio.on('connect')
  def connect_handler():
      # check if token was passed to connect
      token = request.args.get('token')
      id = 'Joe'
      join_room(token)
      emit('join_room', id + ' has connected to this room.', room=token)
  
  if __name__ == "__main__":
      socketio.run(robotAIapp, host= '0.0.0.0', debug=True)
  </code></pre>
  
  <p>My client code looks like the following:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Flask SocketIO Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Some sample code to make sure Flask-SocketIO works.&lt;/p&gt;
    &lt;button onclick="connectWS()"&gt;Connect&lt;/button&gt;
    &lt;script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"&gt;&lt;/script&gt;
  
    &lt;script type="text/javascript" charset="utf-8"&gt;
      // connect to web socket server
      function connectWS() {
          var socket = io.connect('http://ec2-13-54-68-85.ap-southeast-2.compute.amazonaws.com', 
              {rememberTransport: false, query: "token=1234567890POIUYTREWQ" } 
          );
  
          // verify our websocket connection is established
          socket.on('connect', function() {
              console.log('Websocket connected!');
          });
  
          // message handler for 'join_room' messages
          socket.on('join_room', function(msg) {
              console.log('join_room ' + msg);
          });
      }
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And finally, the relevant bits from my NGINX config are</p>
  
  <pre><code>    #Redirect to API
      #--------------------------------------------------------------
      location /api/ {
          proxy_pass http://127.0.0.1:5000/;
      }
  
      #Redirect web socket connections
      #--------------------------------------------------------------
      location /socket.io {
          #include proxy_params;
          proxy_http_version 1.1;
          proxy_buffering off;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
          proxy_pass http://127.0.0.1:5000/socket.io;
      }
  </code></pre>