Flutter websocket connection issue - Connection not upgraded to websocket

Viewed 607
IO.Socket socket = IO.io('https://*****.com/*****/');
socket.connect();
socket.io.options['extraHeaders'] = {
  'foo': 'bar',
  'Authorization': 'Bearer $_token',
};
socket.onConnect((_) {
  print('connect');
  socket.emit('msg', 'test');
});

socket.on('event', (data) => print(data));
socket.onDisconnect((_) => print('disconnect'));
socket.onConnectError((handler) => print(handler.toString()));
socket.onError((_) => print('onError'));
socket.on('fromServer', (_) => print(_));

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

1 Answers

I have the same issue

I have the chat service (with SocketIO + Strapi) and it works fine if it is in localhost/private_IP, I can connect my emulated devices an my cellphone to my service chat

But I have to deploy it with docker and nginx, For this I have my docker_compose.yaml

chat:
  image: strapi/strapi
  volumes:
    - ./chat:/srv/app
  ports:
    - '3000:3000'
  # build:
  #   ./backend/backend
  environment:
    DATABASE_CLIENT: chatDB
    DATABASE_HOST: chatDB
    DATABASE_NAME: databaseName
    DATABASE_PORT: 27017
    DATABASE_USERNAME: root
    DATABASE_PASSWORD: databasePass
  links:
    - chatDB

And my location-nginx

location /chat/ {
    rewrite ^/chat/(.*)$ /$1 break;
    proxy_pass http://chat:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass_request_headers on;
}

The chat service kinda works, because if I make a request to /chat/users I have a response

PD: I'm awful with Nginx

Related