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

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

Open fldvlpr opened this issue 3 years ago • 8 comments

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.

fldvlpr avatar Oct 18 '21 10:10 fldvlpr

same problem

Gazzolla avatar Oct 27 '21 13:10 Gazzolla

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

Gazzolla avatar Oct 27 '21 13:10 Gazzolla

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

jumperchen avatar Dec 17 '21 02:12 jumperchen

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

jumperchen avatar Dec 17 '21 02:12 jumperchen

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

  • Physical Device
  • socket_io_client: ^2.0.0-beta.4-nullsafety.0
  • Change server socket version
  • Flutter clean and rebuild

Flutter 2.8.1

joeserhtf avatar Jan 12 '22 19:01 joeserhtf

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.

Advait1306 avatar Jan 24 '22 05:01 Advait1306

i have the same problem

valdesguefa avatar May 19 '22 06:05 valdesguefa

i have the same problem , plz help anyone

Ashwani-Salaria avatar May 22 '22 06:05 Ashwani-Salaria