rikulo / socket.io-client-dart

socket.io-client-dart: Dartlang port of socket.io-client https://github.com/socketio/socket.io-client
https://quire.io
MIT License
675 stars 184 forks source link

Not act to connecting or not connection #60

Open tazik561 opened 4 years ago

tazik561 commented 4 years ago

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?

jumperchen commented 4 years ago

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

tazik561 commented 4 years ago

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.

jumperchen commented 4 years ago

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

tazik561 commented 4 years ago

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?

jumperchen commented 4 years ago

@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.