socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Not act to connecting or not connection

Open tazik561 opened this issue 5 years ago • 5 comments

I am using this code to connect to socket io server :

  @override
  void initState() {
    super.initState();
    IO.Socket socket = IO.io('https://socket.***.**', <String, dynamic>{
      'transports': ['websocket'],
      'autoConnect': true,
    });
//    socket.connect();

    socket.on('connect', (_) {
      print('connect');
      socket.emit('msg', 'test');
    });

    socket.on('connecting', (data) => print("connecting"));
    socket.on('reconnect', (data) => print("reconnect"));
    socket.on('reconnect_attempt', (data) => print("reconnect_attempt"));
    socket.on('reconnect_failed', (data) => print("reconnect_failed"));
    socket.on('reconnect_error', (data) => print("reconnect_error"));
    socket.on('reconnecting', (data) => print("reconnecting"));
    socket.on('event', (data) => print(data));
    socket.on('ping', (data) => print("pinging"));
    socket.on('error', (error) {
      print('error');
      print(error);
    });
    socket.on('receive_message', (data) => print(data));
    socket.on('disconnect', (_) => print('disconnect'));
    socket.on('fromServer', (_) => print(_));

    socket.open();
  }

But after running i got this messages:

I/flutter ( 9336): reconnecting
I/flutter ( 9336): reconnect_error
I/flutter ( 9336): reconnect_attempt
I/flutter ( 9336): reconnecting

What is a problem ? and how can i find out that what is a problem?

tazik561 avatar Feb 19 '20 16:02 tazik561

This example works for me - https://github.com/rikulo/socket.io-client-dart/issues/36#issuecomment-588580832

jumperchen avatar Feb 20 '20 02:02 jumperchen

socker server that i use , used https and implemented with c# . those code have not difference to my code and i still can not able to connect to https server.

tazik561 avatar Feb 20 '20 09:02 tazik561

@tazik561 is that server (c#) a Socket.io NodeJS-compliant server? If so, it should work.

jumperchen avatar Feb 20 '20 10:02 jumperchen

I do not know and i will ask a developer who write server .But this is other question i asked in stackoverflow: https://stackoverflow.com/questions/60302062/flutter-engineioexception-websocket-error . I used adhara and with this library i got error too. in this question i mentioned that with socket.io tester chrome extention i can connect to server but flutter libraries can not connect to server!! What is your idea? What is my problem?

tazik561 avatar Feb 20 '20 12:02 tazik561

@tazik561 can you try to run the pure dart code first, if it can connect to your server, then the problem may be only inside the flutter env. issue, if not, then I think the problem may be the websocket protocol issue, because the dart:io can only support websocket protocol and it's different from browser dart:html which uses poll protocol first and then switches to websocket if possible. So according to your post on stackoverflow, I could guess the chrome plugin using poll protocol to connect to your server at the first time.

jumperchen avatar Feb 21 '20 02:02 jumperchen