Connecting Flask Socket.IO Server and Flutter Connecting Flask Socket.IO Server and Flutter flask flask

Connecting Flask Socket.IO Server and Flutter


I know this is an older question but hopefully this answer will help someone down the road.

The issue may be caused by the lack of support for polling in flutter.

from: https://github.com/rikulo/socket.io-client-dart#usage-flutter

In Flutter env. it only works with dart:io websocket, not with dart:html websocket, so in this case you have to add 'transports': ['websocket'] when creates the socket instance.

IO.Socket socket = IO.io('http://localhost:3000', <String, dynamic>{    'transports': ['websocket'],    'extraHeaders': {'foo': 'bar'} // optional});

The default Flask development server doesn't support websockets so you'll need to use another server. Thankfully it's simple to get eventlet working with Flask. All you should have to do is install the eventlet package using pip.

pip install eventlet

Once eventlet is installed socketio will detect and use it when running the server.

You can use chrome to double check what transport method is being used. Open your chrome dev tools Ctrl+Shift+I in Windows and go to the Network tab. On each network request you should see either transport=polling or transport=websocket