Hello, there is a bug in the emitting of events received by the client during connection establishment. Since the connection is being established, these events will not be immediately emit to the corresponding listener for processing, but will be stored in a buffer and processed after the connection is established. However, the event name is not removed during processing and is passed to the corresponding listener together.
Here is a demo to reproduce the bug.
Server
netty-socketio version: 1.7.19
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.annotation.OnConnect;
public class SocketIOServerApplication {
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.setHostname("localhost");
configuration.setPort(8080);
SocketIOServer socketServer = new SocketIOServer(configuration);
// You need to add a custom namespace and listener here.
// Do not use the default namespace.
socketServer.addNamespace("/my-namespace").addListeners(new MyNamespaceListener());
socketServer.start();
}
public static class MyNamespaceListener {
// Listen for the connect event.
@OnConnect
public void onConnect(SocketIOClient client) {
// Send an event here.
// The event name is debug and the data is "test".
client.sendEvent("debug", "test");
}
}
}
Client
Socket.IO java client version: 1.0.1
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
import java.net.URISyntaxException;
import java.util.Arrays;
public class SocektIOClient {
public static void main(String[] args) throws URISyntaxException {
// Establish a connection with the socket-io server through the custom namespace.
Socket socket = IO.socket("http://localhost:8080/my-namespace");
// Listen for the event named debug.
socket.on("debug", new Emitter.Listener() {
@Override
public void call(Object... args) {
// Print the args.
// The args is [debug, test], which contains the event name, but the expected args is [test].
System.out.println(Arrays.toString(args));
}
});
socket.open();
}
}
Here are some screenshots of my debugging.
Solution
It is correct for the client to handle the event in connected status. Just keep consistent with the processing of this.
Problem
Hello, there is a bug in the emitting of events received by the client during connection establishment. Since the connection is being established, these events will not be immediately emit to the corresponding listener for processing, but will be stored in a buffer and processed after the connection is established. However, the event name is not removed during processing and is passed to the corresponding listener together.
Here is a demo to reproduce the bug.
Server
netty-socketio version:
1.7.19
Client
Socket.IO java client version:
1.0.1
Here are some screenshots of my debugging.
Solution
It is correct for the client to handle the event in connected status. Just keep consistent with the processing of this.
io.socket.client.Socket#onevent