title: Error when trying to connect flutter app to web socket
body: <p>im trying to connect my flutter app with websocket, i guess server side is working fine but getting error below in client side, any idea why ? And also read similar questions, usually they say 'it's about device connection' but i can work with restful api's in my emulator so i think that's not the issue.</p>
  <p><strong>Error</strong></p>
  <pre><code> WebSocketException: Connection to 'http://localhost:8080/socket.io/?EIO=3&amp;transport=websocket#' was not upgraded to websocket
  </code></pre>
  <p><strong>Client Side</strong></p>
  <pre><code> import 'dart:async';
      import 'package:flutter/material.dart';
      import 'package:live_chat_mongo/function.dart';
      import 'package:live_chat_mongo/models/Message.dart';
      import 'package:socket_io_client/socket_io_client.dart' as IO;
      
      import 'package:socket_io_client/socket_io_client.dart';
      
      // STEP1:  Stream setup
      class StreamSocket {
        final _socketResponse = StreamController&lt;String&gt;();
      
        void Function(String) get addResponse =&gt; _socketResponse.sink.add;
      
        Stream&lt;String&gt; get getResponse =&gt; _socketResponse.stream;
      
        void dispose() {
          _socketResponse.close();
        }
      }
      
      StreamSocket streamSocket = StreamSocket();
      
      //STEP2: Add this function in main function in main.dart file and add incoming data to the stream
      void connectAndListen() {
        IO.Socket socket = IO.io('http://localhost:8080/v1',
            OptionBuilder().setTransports(['websocket']).build());
        socket.onConnectError((data) =&gt; print(data));
        socket.onConnect((_) {
          print('connect');
        });
      
        //When an event recieved from server, data is added to the stream
        socket.on('event', (data) =&gt; streamSocket.addResponse);
        socket.onDisconnect((_) =&gt; print('disconnect'));
      }
      
      //Step3: Build widgets with streambuilder
      
      class BuildWithSocketStream extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return Container(
            child: StreamBuilder(
              stream: streamSocket.getResponse,
              builder: (BuildContext context, AsyncSnapshot&lt;String&gt; snapshot) {
                return Container(
                  child: Text('ds'),
                );
              },
            ),
          );
        }
      }
      
      void main() {
        connectAndListen();
        runApp(MaterialApp(home: BuildWithSocketStream()));
      }
  </code></pre>
  <p><strong>Server Side</strong></p>
  <pre><code>require(&quot;dotenv&quot;).config({ path: &quot;variables.env&quot; });
  
  require(&quot;./app/services/mongo&quot;);
  // require('./app/services/redis');
  
  require(&quot;./app/models/User.js&quot;);
  require(&quot;./app/models/Event.js&quot;);
  require(&quot;./app/models/Committee.js&quot;);
  require(&quot;./app/models/Comment.js&quot;);
  require(&quot;./app/models/EventSession.js&quot;);
  require(&quot;./app/models/Subscription.js&quot;);
  require(&quot;./app/models/Form.js&quot;);
  require(&quot;./app/models/Application.js&quot;);
  require(&quot;./app/models/Announcement.js&quot;);
  require(&quot;./app/models/MailToken.js&quot;);
  require(&quot;./app/models/MailError.js&quot;);
  require(&quot;./app/models/BlogPost.js&quot;);
  require(&quot;./app/models/BlogComment.js&quot;);
  require(&quot;./app/models/BlogCategory.js&quot;);
  
  const app = require(&quot;./app&quot;);
  var http = require(&quot;http&quot;).Server(app);
  var io = require(&quot;socket.io&quot;)(http);
  io.on(&quot;connection&quot;, (s) =&gt; {
    console.log(&quot;socket.io connection&quot;);
  
  });
  app.set(&quot;port&quot;, process.env.PORT || 7070);
  const server = app.listen(app.get(&quot;port&quot;), () =&gt; {
    console.log(`Express running → localhost:${server.address().port}`);
  });
  </code></pre>