socket.io-client-dart
socket.io-client-dart copied to clipboard
Flutter - "HttpException: Connection closed before full header was received" when trying to connect via socket client chat
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.
same problem
@fldvlpr try using socket_io_client: ^2.0.0-beta.4-nullsafety.0 in your pubspec.yaml
@fldvlpr FYI: https://stackoverflow.com/questions/55879550/how-to-fix-httpexception-connection-closed-before-full-header-was-received
@fldvlpr Next time DO NOT USE @
to mention anyone for your own question, this is a open source project (which is free to use)
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
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.
i have the same problem
i have the same problem , plz help anyone