Reputation: 261
I have to implement client functionality using https://github.com/socketio/socket.io-client-java. I have socket.io nodejs server 4.x version. I want to establish around 300-700 socket connections using threadpool ThreadPoolExecutor
in a loop after some fixed delay. I have tried to implement this, the socket connections to server established but after sometimes got disconnected.Please help me figure the root cause of the issue of disconnections.
I have tired
Without using threads at all.
Using singleThreadPool
Using fixedThreadPool
Using scheduledThreadPool
ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(200);
ScheduledFuture<?> future;
future= executor.scheduleAtFixedRate(() -> {
for(int i=1;i<=300;i++) {
IO.Options options = IO.Options.builder()
.setPath("/agent-manager/socket.io")
.setTransports(new String[]{Polling.NAME,WebSocket.NAME})
.setAuth(token)
.build();
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]);
}
}).on("connect", new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println(socket.id() +" "+i+" connected");
}
}).on("disconnect", new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println(socket.id() +" "+i+" disconnected");
}
});
socket.connect();
lock.countDown();
}
}, 1000, delay, TimeUnit.MILLISECONDS);
lock.await(delay, TimeUnit.MILLISECONDS);
future.cancel(true);
In all above cases, disconnections appear after few seconds. Is there some sort of socket object ttl expiration, connection timeout, or server & client are not sending any data in some time, so due to inactivity the disconnections appears? How to keep connections sustained?
Upvotes: 1
Views: 312