socket.io-client-java
socket.io-client-java copied to clipboard
Polling and Websocket have different effect in event callback
same code, but different effect for various protocols
for:
client1.on(testEvent, args -> {
receivedData1.set(args[0]);
});
For Polling:
For Websocket:
@darrachequesne @nkzawa
@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 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