Open codesdevs opened 1 year ago
pub.dev doesn't have a 3.x version
@codesdevs If you use the socket.io client version 1.0.2, that should work
@codesdevs If you use the socket.io client version 1.0.2, that should work
thank you so much bro it worked. I was on it for more than 4 hrs ;)
yes it still works thank you every much for node js server : "socket.io": "^2.4.1" for yaml file socket_io_client: ^1.0.2
I have set up a Node.js server with "socket.io": "^2.4.1"
, and I'm using "socket_io_client: ^1.0.2"
in my Flutter project. If you'd like to check whether the connection is working, here's the code I used:
dependencies:
socket_io_client: ^1.0.2
import 'package:socket_io_client/socket_io_client.dart' as IO;
class SocketClient {
IO.Socket? socket;
static SocketClient? _instance;
// Private constructor
SocketClient._internal() {
// Initialize and connect to the socket server
socket = IO.io('http://Your Ip address:Port', //ex https://198.256.0.0:3000
IO.OptionBuilder().setTransports(['websocket']) // Enable WebSocket transport
.disableAutoConnect() // Disable auto-connect
.build()
);
socket!.connect();
// Add event listeners
socket!.onConnect((_) {
print('Connected to server');
});
socket!.onDisconnect((_) {
print('Disconnected from server');
});
socket!.onConnectError((error) {
print('Connection error: $error');
});
}
// Singleton pattern
static SocketClient get instance {
_instance ??= SocketClient._internal(); // Lazy initialization
return _instance!;
}
}
Make sure the server IP address is correct, and your Flutter app is allowed to access it.
I'm Android flutter. How do I fix this? I still have problems with 3.x references