Skip to content

Commit e4f9507

Browse files
update site
- how to create a lot of clients
1 parent 2ed5f81 commit e4f9507

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

faq.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ <h1>Frequently asked questions</h1>
7474
<ul>
7575
<li><a href="#How_to_deal_with_cookies">How to deal with cookies</a></li>
7676
<li><a href="#How_to_use_with_AWS_Load_Balancing">How to use with AWS Load Balancing</a></li>
77-
<li><a href="#How_to_force_TLS_v1.2_and_above">How to force TLS v1.2 and above</a></li></ul>
77+
<li><a href="#How_to_force_TLS_v1.2_and_above">How to force TLS v1.2 and above</a></li>
78+
<li><a href="#How_to_create_a_lot_of_clients">How to create a lot of clients</a></li></ul>
7879
<section>
7980
<h2><a name="How_to_deal_with_cookies"></a>How to deal with cookies</h2>
8081
<p>In order to store the cookies sent by the server and include them in all subsequent requests, you need to create an OkHttpClient with a custom <a class="externalLink" href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-cookie-jar/">cookie jar</a>.</p>
@@ -210,7 +211,33 @@ <h2><a name="How_to_force_TLS_v1.2_and_above"></a>How to force TLS v1.2 and abov
210211
Socket socket = IO.socket(URI.create(&quot;https://example.com&quot;), options);
211212
</pre></div></div>
212213

213-
<p>Note: we will upgrade to OkHttp 4 in the next major version.</p></section>
214+
<p>Note: we will upgrade to OkHttp 4 in the next major version.</p></section><section>
215+
<h2><a name="How_to_create_a_lot_of_clients"></a>How to create a lot of clients</h2>
216+
<p>By default, you won&#x2019;t be able to create more than 5 Socket.IO clients (any additional client will be disconnected with &#x201c;transport error&#x201d; or &#x201c;ping timeout&#x201d; reason). That is due to the default OkHttp <a class="externalLink" href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dispatcher/">dispatcher</a>, whose <code>maxRequestsPerHost</code> is set to 5 by default.</p>
217+
<p>You can overwrite it by providing your own OkHttp client:</p>
218+
219+
<div class="source">
220+
<div class="source"><pre class="prettyprint">int MAX_CLIENTS = 100;
221+
222+
Dispatcher dispatcher = new Dispatcher();
223+
dispatcher.setMaxRequests(MAX_CLIENTS * 2);
224+
dispatcher.setMaxRequestsPerHost(MAX_CLIENTS * 2);
225+
226+
OkHttpClient okHttpClient = new OkHttpClient.Builder()
227+
.dispatcher(dispatcher)
228+
.readTimeout(1, TimeUnit.MINUTES) // important for HTTP long-polling
229+
.build();
230+
231+
IO.Options options = new IO.Options();
232+
options.callFactory = okHttpClient;
233+
options.webSocketFactory = okHttpClient;
234+
235+
for (int i = 0; i &lt; MAX_CLIENTS; i++) {
236+
Socket socket=IO.socket(URI.create(&quot;https://example.com&quot;), options);
237+
}
238+
</pre></div></div>
239+
240+
<p>Note: we use <code>MAX_CLIENTS * 2</code> because a client in HTTP long-polling mode will have one long-running GET request for receiving data from the server, and will create a POST request for sending data to the server.</p></section>
214241
</main>
215242
</div>
216243
</div>

0 commit comments

Comments
 (0)