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.32k stars 972 forks source link

unable to connect with netty-socketio #683

Closed mrez9 closed 3 years ago

mrez9 commented 3 years ago

i want to connect from "socket.io-client-java" to "netty-socketio" to send and receive data. client

try {
            socketTCP = IO.socket("http://192.168.1.8:9092");
            socketTCP.connect();
            Log.d(TAG, "onCreate: try:  socket:  " + socketTCP.connected());

        } catch (Exception e) {
            Log.d(TAG, "socketError:  " + e.getMessage());
            e.printStackTrace();
        }
        Log.d(TAG, "onCreate: socket:  " + socketTCP.connected());
        socketTCP.emit("event,"test");

server

        Configuration configuration = new Configuration();
        configuration.setHostname("localhost");
        configuration.setPort(9092);

        SocketIOServer server = new SocketIOServer(configuration);

        server.addEventListener("event", String.class, new DataListener<String>() { ... }

but socketTCP dosen't connect and no exception throwing

by the way, connecting from same client(version 2.0.1) to socket.io.js(version 4.1.3) is working fine then i know its not from ip or port

i tried this version but still not working: client version 0.9.+ with netty-socket 1.6.6 client version 1.0.1 with netty-socket 1.7.19 client version 1.0.+ with netty-socket 1.7.19 client version 2.0.+ with netty-socket 1.7.19

I really appreciate any help you can provide

mrez9 commented 3 years ago

i realized my issue wasn't versions problem, client 1.0.1 works fine with netty server 1.7.19

       <dependency>
            <groupId>com.corundumstudio.socketio</groupId>
            <artifactId>netty-socketio</artifactId>
            <version>1.7.19</version>
        </dependency>
        <dependency>
            <groupId>io.socket</groupId>
            <artifactId>socket.io-client</artifactId>
            <version>1.0.1</version>
        </dependency>

my problem was the way of emitting and listening: i can only use String:

server:

 server.addEventListener("join", String.class, new DataListener<String>() {
            @Override
            public void onData(SocketIOClient socketIOClient, String s, AckRequest ackRequest) {

                System.out.println("join" + s);
            }
        });

client:

socket.emit("join", "hello world");

TIP: to passing other object create JsonObject or JsonArray and pass it as string