|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <!-- |
3 | | - | Generated by Apache Maven Doxia Site Renderer 1.9.2 from src/site/markdown/initialization.md at 2022-07-07 |
| 3 | + | Generated by Apache Maven Doxia Site Renderer 1.9.2 from src/site/markdown/initialization.md at 2022-07-08 |
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: 2022-07-07<span class="divider">|</span> |
| 35 | + <li id="publishDate">Last Published: 2022-07-08<span class="divider">|</span> |
36 | 36 | </li> |
37 | 37 | <li id="projectVersion">Version: 2.0.2-SNAPSHOT</li> |
38 | 38 | </ul> |
@@ -105,7 +105,8 @@ <h1>Initialization</h1> |
105 | 105 | <li><a href="#SSL_connections">SSL connections</a> |
106 | 106 | <ul> |
107 | 107 | <li><a href="#With_a_keystore">With a keystore</a></li> |
108 | | -<li><a href="#Trust_all_certificates">Trust all certificates</a></li></ul></li></ul> |
| 108 | +<li><a href="#Trust_all_certificates">Trust all certificates</a></li></ul></li> |
| 109 | +<li><a href="#Multiplexing">Multiplexing</a></li></ul> |
109 | 110 | <section> |
110 | 111 | <h2><a name="Creation_of_a_Socket_instance"></a>Creation of a Socket instance</h2> |
111 | 112 |
|
@@ -513,7 +514,62 @@ <h3><a name="Trust_all_certificates"></a>Trust all certificates</h3> |
513 | 514 | options.webSocketFactory = okHttpClient; |
514 | 515 |
|
515 | 516 | Socket socket = IO.socket(URI.create("https://example.com"), options); |
516 | | -</pre></div></div></section></section> |
| 517 | +</pre></div></div> |
| 518 | +</section></section><section> |
| 519 | +<h2><a name="Multiplexing"></a>Multiplexing</h2> |
| 520 | +<p>The Java client does support multiplexing: this allows to split the logic of your application into distinct modules, while using one single WebSocket connection to the server.</p> |
| 521 | +<p>Reference: <a class="externalLink" href="https://socket.io/docs/v4/namespaces/">https://socket.io/docs/v4/namespaces/</a></p> |
| 522 | + |
| 523 | +<div class="source"> |
| 524 | +<div class="source"><pre class="prettyprint">Socket socket = IO.socket(URI.create("https://example.com")); // the main namespace |
| 525 | +Socket productSocket = IO.socket(URI.create("https://example.com/product")); // the "product" namespace |
| 526 | +Socket orderSocket = IO.socket(URI.create("https://example.com/order")); // the "order" namespace |
| 527 | + |
| 528 | +// all 3 sockets share the same Manager |
| 529 | +System.out.println(socket.io() == productSocket.io()); // true |
| 530 | +System.out.println(socket.io() == orderSocket.io()); // true |
| 531 | +</pre></div></div> |
| 532 | + |
| 533 | +<p>Please note that multiplexing will be disabled in the following cases:</p> |
| 534 | +<ul> |
| 535 | + |
| 536 | +<li>multiple creation for the same namespace</li> |
| 537 | +</ul> |
| 538 | + |
| 539 | +<div class="source"> |
| 540 | +<div class="source"><pre class="prettyprint">Socket socket = IO.socket(URI.create("https://example.com")); |
| 541 | +Socket socket2 = IO.socket(URI.create("https://example.com")); |
| 542 | + |
| 543 | +System.out.println(socket.io() == socket2.io()); // false |
| 544 | +</pre></div></div> |
| 545 | + |
| 546 | +<ul> |
| 547 | + |
| 548 | +<li>different domains</li> |
| 549 | +</ul> |
| 550 | + |
| 551 | +<div class="source"> |
| 552 | +<div class="source"><pre class="prettyprint">Socket socket = IO.socket(URI.create("https://first.example.com")); |
| 553 | +Socket socket2 = IO.socket(URI.create("https://second.example.com")); |
| 554 | + |
| 555 | +System.out.println(socket.io() == socket2.io()); // false |
| 556 | +</pre></div></div> |
| 557 | + |
| 558 | +<ul> |
| 559 | + |
| 560 | +<li>usage of the <a href="#forceNew">forceNew</a> option</li> |
| 561 | +</ul> |
| 562 | + |
| 563 | +<div class="source"> |
| 564 | +<div class="source"><pre class="prettyprint">IO.Options options = IO.Options.builder() |
| 565 | + .setForceNew(true) |
| 566 | + .build(); |
| 567 | + |
| 568 | +Socket socket = IO.socket(URI.create("https://example.com")); |
| 569 | +Socket socket2 = IO.socket(URI.create("https://example.com/admin"), options); |
| 570 | + |
| 571 | +System.out.println(socket.io() == socket2.io()); // false |
| 572 | +</pre></div></div></section> |
517 | 573 | </main> |
518 | 574 | </div> |
519 | 575 | </div> |
|
0 commit comments