socket.io-client-dart
socket.io-client-dart copied to clipboard
Socket not connect in Real Device ( Android & iOS both)
HERE IS MY FLUTTER DOCTOR : [✓] Flutter (Channel stable, 3.0.1, on macOS 11.6 20G165 darwin-x64, localeen-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.67.2) [✓] Connected device (5 available) [✓] HTTP Host Availability
//HERE IS MY CODE
class SocketInit {
static IO.Socket? socket;
static socketInit() async {
socket = IO.io(
ApiUtils.socketUrl,
IO.OptionBuilder().setTransports(['websocket']).enableAutoConnect().setExtraHeaders({'foo': 'bar'}).enableForceNewConnection().build(),
);
socket!.connect();
debugPrint(" socket!.connected --- ${socket!.connected.toString()}");
socket!.onConnect((data) {
debugPrint("Socket Connect Successfully! ");
});
socket!.on("1", (data) {
debugPrint("socket.on ----------- $data");
SocketCommentResponse commentResponse = SocketCommentResponse.fromJson(jsonDecode(jsonEncode(data)));
sendBroadcast(BroadcastUtils.liveComment, extras: jsonDecode(jsonEncode(commentResponse)));
debugPrint('sendBroadCast --- ${commentResponse.toJson().toString()}');
});
socket!.once("1", (data) {
debugPrint('once ----------- $data');
});
}
static disposeSocket() {
if (socket != null && socket!.connected) {
socket!.dispose();
}
}
}
did you fix your problem ? i have same problem
i have same problem too
@renysh i fixed my problem by using 2.0.0-beta.4-nullsafety.0 version dont use version 1.0.2 socket_io_client: ^2.0.0-beta.4-nullsafety.0
I can confirm that using the 2.0.0 pre release version fixed my problem when using "socket.io": "4.5.1",
I can confirm that using the 2.0.0 pre release version fixed my problem when using "socket.io": "4.5.1",
HI, can you please confirm whether when internet connection is turned off and then on, does it connect to the existing last socket connection (on a real physical device)?
For me, on emulator, the socket reconnects when internet is back on (as expected), but on a physical device it just throws SocketException
immediately after internet disconnects (No such exception when turn off internet in android emulator)
I have same problem. I using socket_io_client: ^2.0.0-beta.4-nullsafety.0 and Flask-SocketIO 5.3.2 but it still can’t connect in Real Device.