title: flutter listen to socket.io channel of local nodejs
body: <p>I am trying to listen to socket.io public channel (created from nodejs local server).</p>
  <p>I am using android emulator for testing.</p>
  <p><strong>Code snippet in main.dart:</strong></p>
  <pre><code>import 'package:socket_io_client/socket_io_client.dart' as IO;
  
      IO.Socket socket = IO.io('http://10.0.2.2:3000');
  
          socket.on('connect', (_) {
           print('connect');
           socket.emit('msg', 'test');
          });
          socket.on('event', (data) =&gt; print(data));
          socket.on('disconnect', (_) =&gt; print('disconnect'));
          socket.on('fromServer', (_) =&gt; print(_));
  </code></pre>
  <p>This is the channel, I am trying to listen to:</p>
  <pre><code>global.io.emit('news', { hello: 'world' });
  </code></pre>
  <p>I tried adhara_socket_io.dart' and this package as well (<a href="https://github.com/kakajansh/echo" rel="nofollow noreferrer">https://github.com/kakajansh/echo</a>), with no success.</p>
  <p>Appreciate your assistance.</p>
  <p><strong>Update</strong></p>
  <p>I am trying to use instead this package (<a href="https://github.com/infitio/flutter_socket_io/blob/master/example/lib/main.dart" rel="nofollow noreferrer">https://github.com/infitio/flutter_socket_io/blob/master/example/lib/main.dart</a>)</p>
  <pre><code>const String uri = 'http://127.0.0.1:3000/';
  
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    _MyHomePageState();
    
    List&lt;String&gt; toPrint = [&quot;trying to connect&quot;];
    SocketIOManager manager;
    Map&lt;String, bool&gt; _isProbablyConnected = {};
    Map&lt;String, SocketIO&gt; sockets = {};
  
    @override
    void initState() {
      super.initState();
      manager = SocketIOManager();
      initSocket(&quot;default&quot;);
  
    }
  
  initSocket(String identifier) async {
      setState(() =&gt; _isProbablyConnected[identifier] = true);
      SocketIO socket = await manager.createInstance(SocketOptions(
        //Socket IO server URI
          uri,
          nameSpace: (identifier == &quot;namespaced&quot;)?&quot;/adhara&quot;:&quot;/&quot;,
          //Query params - can be used for authentication
          query: {
            &quot;auth&quot;: &quot;--SOME AUTH STRING---&quot;,
            &quot;info&quot;: &quot;new connection from adhara-socketio&quot;,
            &quot;timestamp&quot;: DateTime.now().toString()
          },
          //Enable or disable platform channel logging
          enableLogging: false,
          transports: [Transports.WEB_SOCKET/*, Transports.POLLING*/] //Enable required transport
      ));
      socket.onConnect((data) {
        pprint(&quot;connected...&quot;);
        pprint(data);
        sendMessage(identifier);
      });
       socket.on('news', (data){   // hera is where you receive from `serve`
        print(&quot;news&quot;);
        print(data);
      });
      socket.onConnectError(pprint);
      socket.onConnectTimeout(pprint);
      socket.onError(pprint);
      socket.onDisconnect(pprint);
      socket.on(&quot;type:string&quot;, (data) =&gt; pprint(&quot;type:string | $data&quot;));
      socket.on(&quot;type:bool&quot;, (data) =&gt; pprint(&quot;type:bool | $data&quot;));
      socket.on(&quot;type:number&quot;, (data) =&gt; pprint(&quot;type:number | $data&quot;));
      socket.on(&quot;type:object&quot;, (data) =&gt; pprint(&quot;type:object | $data&quot;));
      socket.on(&quot;type:list&quot;, (data) =&gt; pprint(&quot;type:list | $data&quot;));
      socket.on(&quot;message&quot;, (data) =&gt; pprint(data));
      socket.connect();
      sockets[identifier] = socket;
    }
    sendMessage(identifier) {
      if (sockets[identifier] != null) {
        pprint(&quot;sending message from '$identifier'...&quot;);
        sockets[identifier].emit(&quot;message&quot;, [
          &quot;Hello world!&quot;,
          1908,
          {
            &quot;wonder&quot;: &quot;Woman&quot;,
            &quot;comics&quot;: [&quot;DC&quot;, &quot;Marvel&quot;]
          },
          {
            &quot;test&quot;: &quot;=!./&quot;
          },
          [
            &quot;I'm glad&quot;,
            2019,
            {
              &quot;come back&quot;: &quot;Tony&quot;,
              &quot;adhara means&quot;: [&quot;base&quot;, &quot;foundation&quot;]
            },
            {
              &quot;test&quot;: &quot;=!./&quot;
            },
          ]
        ]);
        pprint(&quot;Message emitted from '$identifier'...&quot;);
      }
    }
  
     bool isProbablyConnected(String identifier){
      return _isProbablyConnected[identifier]??false;
    }
  
  
  pprint(data) {
      setState(() {
        if (data is Map) {
          data = json.encode(data);
        }
        print(data);
        toPrint.add(data);
      });
    }
  </code></pre>
  <p>However, I am getting below error:</p>
  <p>io.socket.engineio.client.EngineIOException: websocket error</p>
  <p>Thanks,</p>