Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Socket io Error on WebSocketException: Connection to was not upgraded to websocket

I use this package and it work properly on test websites but in app I got this Error

WebSocketException: Connection to 'https://socket.excopro.com:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket

and this is my Code

SocketService() {
    var socket = io(
        'https://socket.excopro.com:443/', <String, dynamic>{
      'transports': ['websocket'],
      'autoConnect': true,
    });
    socket.on('connect', (_) {
      print('connect');
      socket.emit('msg', 'test');
    });
      socket.on("connecting", (data) => print('connecting'));
      socket.on('connect_error', (data) {
        print(data);
        socket.emit('msg', 'test');
      }); 
  }
like image 286
Ali Zare Avatar asked Sep 29 '20 18:09

Ali Zare


1 Answers

I have met the same issue.

For my case, I use Nginx as proxy. I solve the issue by added some proxy header to my Nginx configuration.

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

You can refer to this link.

like image 141
Sophanith Chhoun Avatar answered Oct 19 '22 16:10

Sophanith Chhoun