socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.34k stars 977 forks source link

It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible #747

Open codesdevs opened 1 year ago

codesdevs commented 1 year ago

I'm Android flutter. How do I fix this? I still have problems with 3.x references

codesdevs commented 1 year ago

pub.dev doesn't have a 3.x version

SwathingBlock commented 1 year ago

@codesdevs If you use the socket.io client version 1.0.2, that should work

ujju2132 commented 6 months ago

@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 ;)

KalpeshJangir23 commented 2 months ago

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

KalpeshJangir23 commented 2 months ago

This version worked for me and i was able to set up the connection

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:

Flutter (pubspec.yaml)

dependencies:
  socket_io_client: ^1.0.2

Flutter (Dart code)

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.