Search code examples
javasocket.ionetty-socketio

How to customise handshake url of socket io server in JAVA


I need to start a socket io server by using the Netty socket io library in java. And that should be connected by the client with a custom URL.

Normal handshake URL should be like :- http://192.168.1.190:8021/socket.io/?EIO=3&transport=polling&t=15669875

But I need to customise it like follows, how should I do that. http://192.168.1.190:8021/myapp/socket.io/?EIO=3&transport=polling&t=15669875

Code for socket server

public void start() {
    Configuration config = new Configuration();
    config.setHostname(hostIP);
    config.setPort(hostPort);
    socketServer = new SocketIOServer(config);

    // For collecting Socket client ID
    socketServer.addEventListener("Topic", SocketNotificationData.class,
        new DataListener<SocketNotificationData>() {

        @Override
        public void onData(final SocketIOClient client, SocketNotificationData data, final AckRequest ackRequest) throws Exception {

            logger.info(" ----------One socket-- client id - "
                + client.getSessionId().toString());
        }
    });
    socketServer.start();
}

Solution

  • Later I find out the answer

    Configuration config = new Configuration();
    config.setHostname(hostIP);
    config.setPort(hostPort);
    config.setContext("/myapp");