rikulo / socket.io-client-dart

socket.io-client-dart: Dartlang port of socket.io-client https://github.com/socketio/socket.io-client
https://quire.io
MIT License
676 stars 185 forks source link

Flutter - "HttpException: Connection closed before full header was received" when trying to connect via socket client chat #234

Open fldvlpr opened 3 years ago

fldvlpr commented 3 years ago

Hello

I've been trying to integrate socket chat in my project. I'm using flutter SDK 2.2.3 and the version of the package I'm using is "socket_io_client: ^1.0.1" and socket.io version i'm using in my backend is "2.1.1". I'm using the following code,

try {
      // Configure socket transports must be sepecified
      Socket? socket = io(
          "http://202.121.107.91:7004/v1/chat",
          OptionBuilder()
              .setTransports(['websocket'])
              .disableAutoConnect()
              .setPath("/v1/chat")
              .build());

      // Connect to websocket
      socket?.connect();

      // Handle socket events
      socket?.onConnect((data) {
        Logger().e("============== socket onConnect =================");
      });

      socket?.onConnectError((error) {
        Logger().e("============== socket onConnectError =================");
        Logger().e("============== socket error : $error =================");
      });

      socket?.onDisconnect((data) {
        Logger().e("============== socket onDisconnect =================");
        Logger()
            .e("============== socket onDisconnect : $data =================");
      });
    } catch (e) {
      Logger().d("error : ${e.toString()}");
    }

I'm getting an error like,


============== socket onConnectError =================
I/flutter ( 6650): ├ 🚨 ============== socket error : HttpException: Connection closed before full header was received, uri = http://202.121.107.91:7004/socket/?EIO=3&transport=websocket =================

I've also tried with the **"socket_io_client: ^2.0.0-beta.4-nullsafety.0"** version and I'm still getting the same error.

can anyone please let me know the solution?

thanks.
Gazzolla commented 3 years ago

same problem

Gazzolla commented 3 years ago

@fldvlpr try using socket_io_client: ^2.0.0-beta.4-nullsafety.0 in your pubspec.yaml

jumperchen commented 2 years ago

@fldvlpr FYI: https://stackoverflow.com/questions/55879550/how-to-fix-httpexception-connection-closed-before-full-header-was-received

jumperchen commented 2 years ago

@fldvlpr Next time DO NOT USE @ to mention anyone for your own question, this is a open source project (which is free to use)

joeserhtf commented 2 years ago

I'm having the same issue and tried everything that i could find, there is any other solutions know? I tried:

Flutter 2.8.1

Advait1306 commented 2 years ago

Are you sure the server is not crashing when you try to make this connection? I usually have this issue when the server crashes because of some logic in the connect function.

valdesguefa commented 2 years ago

i have the same problem

Ashwani-Salaria commented 2 years ago

i have the same problem , plz help anyone