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

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

Open abinmittu opened this issue 3 years ago • 17 comments

I am trying to connect socket_io_client: ^2.0.0-beta.4-nullsafety.0 to a Nodejs server socket.io - 3.0.3. I am getting error WebSocketException: Connection to 'https://mydomain.com:0/socket.io/?EIO=4&transport=web_socket#' was not upgraded to websocket.

From the read me I suppose version 2.0.0-beta.4-nullsafety.0 is compatible with ```socket.io 3.0.3``

abinmittu avatar May 31 '21 13:05 abinmittu

same problem here on flutter master channel.

srcnysf avatar Jun 07 '21 13:06 srcnysf

Same for me !

evaleiraswembii avatar Jun 07 '21 23:06 evaleiraswembii

@abinmittu Are you using nginx in your server?

kameshkarthi avatar Jun 10 '21 01:06 kameshkarthi

Same for me !

rinku-techindustan avatar Jun 14 '21 09:06 rinku-techindustan

Yes!!

On Wed, 9 Jun 2021 at 22:54 kameshkarthi @.***> wrote:

@abinmittu https://github.com/abinmittu Are you using nginx in your server?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rikulo/socket.io-client-dart/issues/200#issuecomment-858219334, or unsubscribe https://github.com/notifications/unsubscribe-auth/APUDJKPTAZHUIYANLM3YV2TTSALOBANCNFSM4526BTFA .

evaleiraswembii avatar Jun 14 '21 13:06 evaleiraswembii

@evaleiraswembii add this in your nginx config file

location /socket.io/ { proxy_pass http://servers; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

change servers to your domain.

kameshkarthi avatar Jun 14 '21 13:06 kameshkarthi

Is the :0 behind the normal expected behavior?

ghost avatar Jun 17 '21 19:06 ghost

I had the same problem with socket_io_client: ^2.0.0-beta.4-nullsafety.0, nginx and flask-socketio==5.1.0. But the fix provided by @kameshkarthi works fine for me. Thank you so much!

LostInDarkMath avatar Jun 26 '21 13:06 LostInDarkMath

Is the :0 behind the normal expected behavior?

I have the same question , why the port is becoming zero ?

Djihanegh avatar Sep 23 '21 11:09 Djihanegh

@Djihanegh I think the issue is with the file socket_io_client.dart:49. If no port is passed then due to null safety it takes default int value 0.

Solution:

For those who are looking solution for it, pass a port number while connecting. If no custom port by server, for ws pass 80 for wss pass 443. Example:

import 'package:socket_io_client/socket_io_client.dart' as IO;

IO.Socket socket = IO.io(
      'wss://socket.example.com:443',
      IO.OptionBuilder()
          .setTransports(['websocket'])
          .build());

neeraj-htp avatar Dec 13 '21 14:12 neeraj-htp

I have the same problem and my problem started after deploying my Node.js app to Azure. Maybe kameshkarthi's solution works but I don't know if I can change the configuration in Azure.

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

Dam, we're stuck at the moment cause we can't specify a port on the domain. Sucky bug! Has someone made a PR yet?

ollyde avatar May 15 '22 14:05 ollyde

I have the same question , why the port is becoming zero ?

doanngoctu95 avatar May 20 '22 08:05 doanngoctu95

It's a quick fix on the library if you download it. (If someone can make a PR)

Change var id = '${parsed.scheme}://${parsed.host}:${parsed.port}';

To

String port = parsed.port != null ? ":" + parsed.port : "";
var id = '${parsed.scheme}://${parsed.host}${port}';

ollyde avatar May 20 '22 08:05 ollyde

same error ...

enzodanjour avatar May 31 '22 04:05 enzodanjour

brary if you download it. (If someone can make a PR)

i try this, but not working

enzodanjour avatar May 31 '22 04:05 enzodanjour