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

Connection to 'url' was not upgraded to websocket

Open newETA opened this issue 2 years ago • 2 comments

I am having an issue while connecting socket.io to my test server, It works for local but not connecting to the server, I have a server on AWS elasticbeanstalk.

Working code for local: but whenever I changed it to my test server it will not work. Please if anyone has resolved please advise.

void connectManually() {
  Socket socket = io(
      'http://10.0.2.2:5000',
      OptionBuilder()
          .setPath('/rt')
          .setTransports(['websocket']) // for Flutter or Dart VM
          .disableAutoConnect() // disable auto-connection
          .setExtraHeaders({
            'Connection': 'Upgrade',
            'Origin': 'http://server.com'
          }) // optional
          .setQuery({'token': "babaji"})
          .build());
  socket.on('connect_error', (c) {
    log(c.toString());
  });

  socket.connect();

  socket.onConnect((_) {
    print('connected to websocket');
  });
}

FYI I am using: socket_io_client: ^2.0.0-beta.4-nullsafety.0

newETA avatar May 09 '22 11:05 newETA

add param "enableForceNew()" like this " _socket = IO.io( 'ws://${dotenv.env['SERVER_URL']}:80', OptionBuilder().setTransports(['websocket']).setQuery({'token': token}).enableForceNew().build(), );" without this param it create new connection from cache

this helped for me )

holyboom1 avatar Sep 02 '22 14:09 holyboom1

I am also having same error. @holyboom1 Tried your answer also but error is still there.

wdcs-nadimansari avatar May 08 '23 11:05 wdcs-nadimansari