Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm getting on connect_error timeout #63

Open
heshaShawky opened this issue Feb 21, 2020 · 18 comments
Open

I'm getting on connect_error timeout #63

heshaShawky opened this issue Feb 21, 2020 · 18 comments

Comments

@heshaShawky
Copy link

heshaShawky commented Feb 21, 2020

I'm using NodeJS/NestJS for server-side socket.io

And your lib for client-side ( Flutter ) So I first have tried the example code and completely just nothing!!

So then I went to use on with connect_error to check if there are any errors or something and it showed just one word on the console every couple of seconds and it's timeout

@heshaShawky heshaShawky changed the title I'm getting error_connection timeout I'm getting on connect_error timeout Feb 21, 2020
@jumperchen
Copy link
Member

This example works for me - #36 (comment)

@a1245582339
Copy link

I have the same problem with you

@Mavennix
Copy link

This issue still persists. Is there any solution?

@jumperchen
Copy link
Member

Can any example code be shown here?

@boreys
Copy link

boreys commented Jul 3, 2020

The reconnect logic does not work well. Try connect to socket.io and then disable your WiFi, let it error awhile, then enable Wifi back. The reconnect logic is in the failed loop even the internet connection is restored.

@kamyabrs
Copy link

I have the same problem

@jumperchen
Copy link
Member

This example works to me:

Flutter

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;


void main(){
  runApp(
      new MaterialApp(
        title: 'Hello World App',
        home: new MyApp(),
      )
  );
}

class MyApp extends StatefulWidget {
  @override
  _State createState() => new _State();
}

class _State extends State<MyApp>{
  String _textFromServer = "";
  IO.Socket _socket;

  @override
  void initState() {
    super.initState();
    _socket = IO.io('http://10.1.3.95:3000/', <String, dynamic>{'transports': ['websocket'], 'forceNew': true});
    _socket.connect();
    _socket.on("connect", (_) {
          print('Connected');
          Timer.periodic(const Duration(seconds: 1), (Timer countDownTimer) {
            _socket.emit('toServer', json.encode({'key': 'hello', 'value': 'world'}));
        });
    });
    _socket.on("fromServer", (_) {
      print('fromServer $_');
    });
    _socket.on("connect_error", (data) => print('connect_error: $data'));
    _socket.on("reconnect", (data) => print('reconnect: $data'));
    _socket.on("reconnect_failed", (data) => print('reconnect_failed: $data'));
    _socket.on("reconnect_error", (data) => print('reconnect_error: v'));

  }
  void _updateText() {
    _socket.emit('toServer', json.encode({'key': 'hello', 'value': 'world'}));
    print('send text to server');
  }
  @override
  Widget build(BuildContext context) {
    print('build');
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text(_textFromServer),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
       floatingActionButton: FloatingActionButton(
        onPressed: _updateText,
        tooltip: 'Update Text',
        child: Icon(Icons.update),
      ),
      ),
    );
  }
}

Dart Server

import 'package:socket_io/socket_io.dart';

void main() {
  // Dart server
  var io = Server();
  io.on('connection', (client) {
    final headers = client.handshake['headers'];
    headers.forEach((k, v) => print('$k => $v'));

    print('connection default namespace');
    client.on('toServer', (data) {
      print('data from default => $data');
      client.emit('fromServer', '$data');
    });
  });
  io.listen(3000);
}

Result

I/flutter (10590): build
I/flutter (10590): Connected
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): connect_error: SocketException: OS Error: Network is unreachable, errno = 101, address = 10.1.3.95, port = 54218
I/flutter (10590): reconnect_error: v
I/flutter (10590): connect_error: SocketException: OS Error: Network is unreachable, errno = 101, address = 10.1.3.95, port = 54220
I/flutter (10590): reconnect_error: v
I/flutter (10590): connect_error: SocketException: OS Error: Network is unreachable, errno = 101, address = 10.1.3.95, port = 54222
I/flutter (10590): reconnect_error: v
I/flutter (10590): connect_error: SocketException: OS Error: Network is unreachable, errno = 101, address = 10.1.3.95, port = 54224
I/flutter (10590): reconnect_error: v
I/flutter (10590): connect_error: SocketException: OS Error: Network is unreachable, errno = 101, address = 10.1.3.95, port = 54226
I/flutter (10590): reconnect_error: v
I/flutter (10590): reconnect: 6
I/flutter (10590): Connected
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/chatty  (10590): uid=10135(com.example.flutter_app) Thread-2 identical 22 lines
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): fromServer {"key":"hello","value":"world"}
I/flutter (10590): fromServer {"key":"hello","value":"world"}

@Jhellsten
Copy link

I had similar problem when I was starting to test this library for my project and I had 2 problems with the Node.JS server.

First was that I could not use Socket.IO version 3 with, it had same problem on web sockets.
Second thing I did was that I used ngrok for my server and used that one to connect.

@jumperchen
Copy link
Member

@Jhellsten For Socket.io V3, please use v2.0.0-beta version - https://pub.dev/packages/socket_io_client/versions/2.0.0-beta.2

@jatinkatyal13
Copy link

jatinkatyal13 commented Feb 13, 2021

I'm also using a NestJS server and it doesn't seem to connect even when it receives 101 from the server. Following up on all the issues and guidelines in the repository isn't helping and neither is the "it's working for me" comment.

This is what I have written on the client

        IO.io('https://game.stage.codeblitz.app/', <String, dynamic>{
      'transports': ['polling'],
      'port': '443',
      'forceTrue': true
    });

This is what I'm using on web

let g = io('/game', { transport:'websocket', query: { transport: 'websocket', 'X-Game-Id': 'abc' }})

I'm using namespaces, is this what creating the issue? Is there any other thing you'll require to debug this issue?

@binhphi109
Copy link

binhphi109 commented Feb 23, 2022

I'm using

  • nodejs socketio v^3.1.2 and ^4.4.0
  • socketio-client v2.0.0-beta.4-nullsafety.0

and now it works.

Socket socket = io(
      Config.SocketIOUrl,
      OptionBuilder().setTransports(['websocket'])
          .setExtraHeaders({'foo': 'bar'})
          .build());

  socket.onConnectError((error) {
    print('connect');
    socket.emit('chatMessage', 'test');
  });
  socket.onConnect((_) {
    print('connect');
    socket.emit('chatMessage', 'test');
  });
  socket.onDisconnect((_) {
    print('disconnect');
  });

@RikkeiDN-TuPT
Copy link

I'm using

  • nodejs socketio v^3.1.2 and ^4.4.0
  • socketio-client v2.0.0-beta.4-nullsafety.0

and now it works.

Socket socket = io(
      Config.SocketIOUrl,
      OptionBuilder().setTransports(['websocket'])
          .setExtraHeaders({'foo': 'bar'})
          .build());

  socket.onConnectError((error) {
    print('connect');
    socket.emit('chatMessage', 'test');
  });
  socket.onConnect((_) {
    print('connect');
    socket.emit('chatMessage', 'test');
  });
  socket.onDisconnect((_) {
    print('disconnect');
  });

How ???

@Hamid313-coder
Copy link

I have the same error!
I copied your code into another new project and run that but still it can't connect to the server.
My backend is nodjs.
I have a next js web app too and it has no problem with backend. It sends and receive data with no problem.
but in flutter side it's giving timeout error.

@eliffkaragoz
Copy link

eliffkaragoz commented Feb 10, 2023

I have the same error. It was working a few days ago. Even though I changed nothing, it is not working now, it gives a timeout error. Were you able to find a solution ?

@Karthikeya-01
Copy link

Karthikeya-01 commented Feb 16, 2023

I have the same error. It was working a few days ago. Even though I changed nothing, it is not working now, it gives a timeout error. Were you able to find a solution ?

I am having a similar issue, can anyone provide a solution

@Muswamba
Copy link

Same problem here Connect Error: timeout. Anyone can provide us with a solution?

@SabariFuzionest
Copy link

same error

@devSajan
Copy link

devSajan commented Jun 6, 2024

i am trying to load test the app, so when i am using the socket.io-client to create 1000 connections sometimes i am getting Error:timeout. we are using aws k8 and alb for deployment, on localhost it's working fine. k8 pods have 6 to 15% of cpu usage so we have resources available there. So what is the reason for that timeout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests