Closed erma66 closed 1 year ago
Did you find out why? It happened to me
Unfortunately, I have not found the reason, the source code does not have the number 64
Did you find out why? It happened to me
But I found that it was possible to continue the connection by starting a new client
You mean start a new process? The new process is not affected
yes,However, newly started clients can still only create 64 connections
Well, I noticed that each socket Connection starts three threads, perhaps because of the thread count limit?
Hi! I think that's because the maxRequests
value of the underlying OkHttpClient defaults to 64: https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dispatcher/max-requests/
You need to provide a custom dispatcher:
int MAX_CLIENTS = 100;
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(MAX_CLIENTS * 2);
dispatcher.setMaxRequestsPerHost(MAX_CLIENTS * 2);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.dispatcher(dispatcher)
.readTimeout(1, TimeUnit.MINUTES) // important for HTTP long-polling
.build();
IO.Options options = new IO.Options();
options.callFactory = okHttpClient;
options.webSocketFactory = okHttpClient;
for (int i = 0; i < MAX_CLIENTS; i++) {
Socket socket = IO.socket(URI.create("https://example.com"), options);
}
Reference: https://socketio.github.io/socket.io-client-java/faq.html#How_to_create_a_lot_of_clients
Thank you very much. That solves my problem
When I tried to test how many socket connections I could create, I found that only 64 were connected and the rest were disconnected