|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <!-- |
3 | | - | Generated by Apache Maven Doxia Site Renderer 1.9.2 from src/site/markdown/initialization.md at 2021-11-24 |
| 3 | + | Generated by Apache Maven Doxia Site Renderer 1.9.2 from src/site/markdown/initialization.md at 2022-06-29 |
4 | 4 | | Rendered using Apache Maven Fluido Skin 1.9 |
5 | 5 | --> |
6 | 6 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
|
32 | 32 |
|
33 | 33 | <div id="breadcrumbs"> |
34 | 34 | <ul class="breadcrumb"> |
35 | | - <li id="publishDate">Last Published: 2021-11-24<span class="divider">|</span> |
| 35 | + <li id="publishDate">Last Published: 2022-06-29<span class="divider">|</span> |
36 | 36 | </li> |
37 | 37 | <li id="projectVersion">Version: 2.0.2-SNAPSHOT</li> |
38 | 38 | </ul> |
@@ -85,10 +85,16 @@ <h1>Initialization</h1> |
85 | 85 | <li><a href="#rememberUpgrade">rememberUpgrade</a></li> |
86 | 86 | <li><a href="#path">path</a></li> |
87 | 87 | <li><a href="#query">query</a></li> |
88 | | -<li><a href="#extraHeaders">extraHeaders</a></li></ul></li> |
| 88 | +<li><a href="#extraHeaders">extraHeaders</a></li> |
| 89 | +<li><a href="#callFactory">callFactory</a></li> |
| 90 | +<li><a href="#webSocketFactory">webSocketFactory</a></li></ul></li> |
89 | 91 | <li><a href="#Socket_options">Socket options</a> |
90 | 92 | <ul> |
91 | | -<li><a href="#auth">auth</a></li></ul></li></ul></li></ul> |
| 93 | +<li><a href="#auth">auth</a></li></ul></li></ul></li> |
| 94 | +<li><a href="#SSL_connections">SSL connections</a> |
| 95 | +<ul> |
| 96 | +<li><a href="#With_a_keystore">With a keystore</a></li> |
| 97 | +<li><a href="#Trust_all_certificates">Trust all certificates</a></li></ul></li></ul> |
92 | 98 | <section> |
93 | 99 | <h2><a name="Creation_of_a_Socket_instance"></a>Creation of a Socket instance</h2> |
94 | 100 |
|
@@ -318,6 +324,35 @@ <h4><a name="extraHeaders"></a><code>extraHeaders</code></h4> |
318 | 324 | } |
319 | 325 | }); |
320 | 326 | </pre></div></div> |
| 327 | +</section><section> |
| 328 | +<h4><a name="callFactory"></a><code>callFactory</code></h4> |
| 329 | +<p>The <a class="externalLink" href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/">OkHttpClient instance</a> to use for HTTP long-polling requests.</p> |
| 330 | + |
| 331 | +<div class="source"> |
| 332 | +<div class="source"><pre class="prettyprint">OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| 333 | + .readTimeout(1000, TimeUnit.MILLISECONDS) |
| 334 | + .writeTimeout(1000, TimeUnit.MILLISECONDS) |
| 335 | + .build(); |
| 336 | + |
| 337 | +IO.Options options = new IO.Options(); |
| 338 | +options.callFactory = okHttpClient; |
| 339 | + |
| 340 | +Socket socket = IO.socket(URI.create("https://example.com"), options); |
| 341 | +</pre></div></div> |
| 342 | +</section><section> |
| 343 | +<h4><a name="webSocketFactory"></a><code>webSocketFactory</code></h4> |
| 344 | +<p>The <a class="externalLink" href="https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/">OkHttpClient instance</a> to use for WebSocket connections.</p> |
| 345 | + |
| 346 | +<div class="source"> |
| 347 | +<div class="source"><pre class="prettyprint">OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| 348 | + .minWebSocketMessageToCompress(2048) |
| 349 | + .build(); |
| 350 | + |
| 351 | +IO.Options options = new IO.Options(); |
| 352 | +options.webSocketFactory = okHttpClient; |
| 353 | + |
| 354 | +Socket socket = IO.socket(URI.create("https://example.com"), options); |
| 355 | +</pre></div></div> |
321 | 356 | </section></section><section> |
322 | 357 | <h3><a name="Socket_options"></a>Socket options</h3> |
323 | 358 | <p>These settings are specific to the given Socket instance.</p><section> |
@@ -360,15 +395,93 @@ <h4><a name="auth"></a><code>auth</code></h4> |
360 | 395 | <div class="source"> |
361 | 396 | <div class="source"><pre class="prettyprint">options.auth.put("token", "efgh"); |
362 | 397 | socket.disconnect().connect(); |
363 | | -</pre></div></div></section></section></section> |
| 398 | +</pre></div></div> |
| 399 | +</section></section></section><section> |
| 400 | +<h2><a name="SSL_connections"></a>SSL connections</h2><section> |
| 401 | +<h3><a name="With_a_keystore"></a>With a keystore</h3> |
| 402 | + |
| 403 | +<div class="source"> |
| 404 | +<div class="source"><pre class="prettyprint">HostnameVerifier hostnameVerifier = new HostnameVerifier() { |
| 405 | + public boolean verify(String hostname, SSLSession sslSession) { |
| 406 | + return hostname.equals("example.com"); |
| 407 | + } |
| 408 | +}; |
| 409 | + |
| 410 | +KeyStore ks = KeyStore.getInstance("JKS"); |
| 411 | +File file = new File("path/to/the/keystore.jks"); |
| 412 | +ks.load(new FileInputStream(file), "password".toCharArray()); |
| 413 | + |
| 414 | +KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); |
| 415 | +kmf.init(ks, "password".toCharArray()); |
| 416 | + |
| 417 | +TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); |
| 418 | +tmf.init(ks); |
| 419 | + |
| 420 | +SSLContext sslContext = SSLContext.getInstance("TLS"); |
| 421 | +sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); |
| 422 | + |
| 423 | +OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| 424 | + .hostnameVerifier(hostnameVerifier) |
| 425 | + .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) tmf.getTrustManagers()[0]) |
| 426 | + .build(); |
| 427 | + |
| 428 | +IO.Options options = new IO.Options(); |
| 429 | +options.callFactory = okHttpClient; |
| 430 | +options.webSocketFactory = okHttpClient; |
| 431 | + |
| 432 | +Socket socket = IO.socket(URI.create("https://example.com"), options); |
| 433 | +</pre></div></div> |
| 434 | +</section><section> |
| 435 | +<h3><a name="Trust_all_certificates"></a>Trust all certificates</h3> |
| 436 | +<p>Please use with caution, as this defeats the whole purpose of using secure connections.</p> |
| 437 | +<p>This is equivalent to <code>rejectUnauthorized: false</code> for the JavaScript client.</p> |
| 438 | + |
| 439 | +<div class="source"> |
| 440 | +<div class="source"><pre class="prettyprint">HostnameVerifier hostnameVerifier = new HostnameVerifier() { |
| 441 | + @Override |
| 442 | + public boolean verify(String hostname, SSLSession sslSession) { |
| 443 | + return true; |
| 444 | + } |
| 445 | +}; |
| 446 | + |
| 447 | +X509TrustManager trustManager = new X509TrustManager() { |
| 448 | + public X509Certificate[] getAcceptedIssuers() { |
| 449 | + return new X509Certificate[] {}; |
| 450 | + } |
| 451 | + |
| 452 | + @Override |
| 453 | + public void checkClientTrusted(X509Certificate[] arg0, String arg1) { |
| 454 | + // not implemented |
| 455 | + } |
| 456 | + |
| 457 | + @Override |
| 458 | + public void checkServerTrusted(X509Certificate[] arg0, String arg1) { |
| 459 | + // not implemented |
| 460 | + } |
| 461 | +}; |
| 462 | + |
| 463 | +SSLContext sslContext = SSLContext.getInstance("TLS"); |
| 464 | +sslContext.init(null, new TrustManager[] { trustManager }, null); |
| 465 | + |
| 466 | +OkHttpClient okHttpClient = new OkHttpClient.Builder() |
| 467 | + .hostnameVerifier(hostnameVerifier) |
| 468 | + .sslSocketFactory(sslContext.getSocketFactory(), trustManager) |
| 469 | + .build(); |
| 470 | + |
| 471 | +IO.Options options = new IO.Options(); |
| 472 | +options.callFactory = okHttpClient; |
| 473 | +options.webSocketFactory = okHttpClient; |
| 474 | + |
| 475 | +Socket socket = IO.socket(URI.create("https://example.com"), options); |
| 476 | +</pre></div></div></section></section> |
364 | 477 | </main> |
365 | 478 | </div> |
366 | 479 | </div> |
367 | 480 | <hr/> |
368 | 481 | <footer> |
369 | 482 | <div class="container-fluid"> |
370 | 483 | <div class="row-fluid"> |
371 | | - <p>© 2021 |
| 484 | + <p>© 2022 |
372 | 485 | </p> |
373 | 486 | </div> |
374 | 487 | </div> |
|
0 commit comments