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 reshamRudra opened this issue 3 years ago • 12 comments

I am rewriting the existing kotlin app in flutter to support cross-platform. Socket url is working great in kotlin, but it throws an error while using it in flutter. Connection Error - "Connection to 'url' was not upgraded to websocket".

I am using socket_io_client: ^1.0.1.

reshamRudra avatar Aug 26 '21 13:08 reshamRudra

FYI: https://github.com/rikulo/socket.io-client-dart#usage-flutter

jumperchen avatar Aug 30 '21 01:08 jumperchen

Hi @jumperchen , I have already tried this, still getting same result.

here is my code snippet,

final String token = UserManager.sharedInstance.getAuthToken();

mSocket = IO.io(
    UtilsGeneral.getApiBaseUrl(),
    IO.OptionBuilder()
        .setQuery({"token": token})
        .setTransports(['websocket'])
        .setExtraHeaders({'token':token, 'Connection': 'upgrade', 'Upgrade': 'websocket'})
        .enableReconnection()
        .setReconnectionDelay(1)
        .enableForceNew()
        .build());

reshamRudra avatar Aug 30 '21 04:08 reshamRudra

Hi, Is this issue resolved? Am getting the same issue WebSocketException: Connection to ':0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket My code is as follows

IO.Socket socket = IO.io('< mysocketurl >', OptionBuilder()
               .setTransports(['websocket'])
              .setExtraHeaders({'userId': '12345678'}) 
               .build());
   socket.onConnect((_) {
      print('SOCKET CONNECTED');
      socket.emit('msg', 'test');
    });
    socket.on('event', (data) => print(data));
    socket.onDisconnect((_) => print('disconnect'));
    socket.on('fromServer', (_) => print(_));
    socket.on("connect_error", (data) => print("error " + data.toString()));

sujatha2016 avatar Dec 08 '21 04:12 sujatha2016

also getting the same issue, is there a known fix or work around?

FarhanSajid1 avatar Feb 28 '22 09:02 FarhanSajid1

I have the same issue with 2.0.0-beta.4-nullsafety.0. websocket#' was not upgraded to websocket My socket.io. version is "socket.io": "4.4.1"

 _socket = io(
       WebSocketConfiguration.webSocketUrl,
       OptionBuilder()
           .setTransports(['websocket']) // for Flutter or Dart VM
           .disableAutoConnect()
           .setTimeout(10000)
           .setExtraHeaders({'Connection': 'Upgrade','Upgrade':'websocket'}) // optional
           .build());

   _socket.connect();

okan-oz avatar Mar 25 '22 17:03 okan-oz

is there a known fix or work around?

kanal-altyapi avatar Mar 31 '22 17:03 kanal-altyapi

I encounter same issue recently, it is connection error problem as version on client side and server same doesn’t match, try specifying version using https://github.com/rikulo/socket.io-client-dart.

NeesargD avatar May 04 '22 13:05 NeesargD

Are there any updates on this?

I am having the same issue, 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 03:05 newETA

Same issue here. Any update on this?

gb1849 avatar Dec 25 '22 20:12 gb1849

Same here guys, Any updates?

kushal-tm avatar Mar 14 '23 10:03 kushal-tm

i have same error any solution ?

mohamedanwer123 avatar Mar 21 '23 08:03 mohamedanwer123

Hello, We had integrated socket io in our flutter app with odoo backend so we had version mismatch issue, you can check the socket io version you are implementing on app side and socket io version implemented on backend side you will have to find an compatible version for both side, these helped us, hope it help you too

NeesargD avatar Mar 21 '23 14:03 NeesargD