Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java socket io client connection disconnects #723

Open
Areej-Fatima opened this issue Oct 12, 2022 · 0 comments
Open

Java socket io client connection disconnects #723

Areej-Fatima opened this issue Oct 12, 2022 · 0 comments
Labels

Comments

@Areej-Fatima
Copy link

Areej-Fatima commented Oct 12, 2022

I have implemented socket.io client side in java spring boot, using thread pool executor. Now my socket connections are build successfully, but after 50s to 1 minute, they start getting disconnected. How to sustain socket connections? My code is as below

    CountDownLatch lock = new CountDownLatch(200);
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(200);
    ScheduledFuture<?> future;
        for(int i=1;i<=200;i++) {
       
        future= executor.scheduleAtFixedRate(() -> {

            Map<String, String> map = new HashMap<String, String>();
            map.put("token", "abc");

            IO.Options options = IO.Options.builder()
                    .setPath("/socket.io")
                    .setTransports(new String[]{Polling.NAME,WebSocket.NAME})
                    .setAuth(map)
                    .build();

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

            socket.on("connect_error", new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    System.out.println(args[0]);
                }
            });

            socket.on("connect", new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    System.out.println("Socket connection "+i+" successfully created");
                }
            });
            socket.on("disconnect", new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    System.out.println("Socket connection "+i+" disconnected");
                }
            });

            socket.connect();
            lock.countDown();
        }, 1000, delay, TimeUnit.MILLISECONDS);

        lock.await(delay, TimeUnit.MILLISECONDS);
        future.cancel(true);

    }//end of for loop
    executor.shutdown();

My java socket.io-client 2.1.0 is compatible with socket.io server v4.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant