title: Require assistance with simple pure Java 11 WebSocket client example
body: <p>There appears to be very little Java 11 (pure Java non framework based) WebSocket <strong>client</strong> code examples on the web so I'm hoping StackOverflow can come to the rescue for me once again.</p>
  
  <p><a href="https://craftsmen.nl/java-11-is-here-to-stay/" rel="noreferrer">This</a> is the closest I've found, but unfortunately to my (novice) eyes, it doesn't appear to be a complete solution in showing how to consume the data from the WebSocket listener.</p>
  
  <p>Looking at the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/WebSocket.Listener.html#onText(java.net.http.WebSocket,java.lang.CharSequence,boolean)" rel="noreferrer">WebSocket.Listener implementation, the onText</a> callback method I presume would provide what I need, but I'm struggling to figure out how to return the CompletionStage object and some sort of string data from the socket.</p>
  
  <p>This is some test code I have so far.</p>
  
  <p>Would appreciate assistance. Thanks</p>
  
  <pre class="lang-java prettyprint-override"><code>    public class Main {
  
          public static void main(String[] args) {
  
             WebSocketClient wsc = new WebSocketClient();
             wsc.startSocket("ws://demos.kaazing.com/echo");
  
             int i = 0;   
  
             // Bad, very bad
             do {} while (i == 0);
          }
      }
  
  
      public class WebSocketClient implements WebSocket.Listener {
  
          @Override
          public void onOpen(WebSocket webSocket) {
             //...
              System.out.println("Go...Open".concat(
                      webSocket.getSubprotocol()));
          }
  
          @Override
          public CompletionStage&lt;?&gt; onText(WebSocket webSocket, CharSequence data, boolean last) {
             //...
              System.out.println(data.toString());
  
              // How do I return the CompletionStage object
              // return CompletionStage&lt;String&gt;
          }
  
          @Override
          public void onError(WebSocket webSocket, Throwable error) {
             //..
              System.out.println("Bad day! ".concat(webSocket.toString()));
          }
  
          void startSocket(String connection) {
              CompletableFuture&lt;WebSocket&gt; server_cf = HttpClient.
                      newHttpClient().
                      newWebSocketBuilder().
                      buildAsync(URI.create(connection),
                              new WebSocketClient());
              WebSocket server = server_cf.join();
              server.sendText("Hello!", true);
          }
      }
  </code></pre>