socket.io-client-java icon indicating copy to clipboard operation
socket.io-client-java copied to clipboard

Polling and Websocket have different effect in event callback

Open NeatGuyCoding opened this issue 1 month ago • 3 comments

same code, but different effect for various protocols

for:

client1.on(testEvent, args -> {
          receivedData1.set(args[0]);
      });

For Polling:

Image

For Websocket:

Image

NeatGuyCoding avatar Nov 18 '25 03:11 NeatGuyCoding

@darrachequesne @nkzawa

sanjomo avatar Nov 19 '25 04:11 sanjomo

@sanjomo in your screenshot, the events are different ("Y-Solowarm" for HTTP long-polling, "Ronstring" for WebSocket), could it explain your issue?

Repro:

  • server
import { Server } from "socket.io";

const port = process.env.PORT || 3000;
const io = new Server();

setInterval(() => {
  io.emit("echo", {
    a: new Date(),
    b: 1
  });
}, 1000);

io.listen(port);
  • client:
public class Fiddle {

    public static void main(String[] argz) throws Exception {
        IO.Options options = new IO.Options();
        options.transports = new String[] {"polling"};
        // options.transports = new String[] {"websocket"};

        Socket socket = IO.socket(URI.create("http://localhost:3000"), options);

        socket.on("echo", (args) -> {
            System.out.printf("echo: %s\n", args);
        });

        socket.connect();
    }
}

Both transports output:

echo: {"a":"2025-11-20T10:28:44.396Z","b":1}
echo: {"a":"2025-11-20T10:28:45.397Z","b":1}
echo: {"a":"2025-11-20T10:28:46.397Z","b":1}
echo: {"a":"2025-11-20T10:28:47.397Z","b":1}
echo: {"a":"2025-11-20T10:28:48.398Z","b":1}
...

darrachequesne avatar Nov 20 '25 10:11 darrachequesne

@darrachequesne kindly refer to: https://github.com/socketio4j/netty-socketio/blob/main/netty-socketio-core/src/test/java/com/socketio4j/socketio/integration/RoomBroadcastTest.java

which can reproduce the issue

NeatGuyCoding avatar Nov 20 '25 10:11 NeatGuyCoding