Interface WebSocketClient

All Superinterfaces:
ClientBuilderParams, Unwrappable

@UnstableApi public interface WebSocketClient extends ClientBuilderParams, Unwrappable
A WebSocket client. This client has a few different default values for ClientOptions from WebClient because of the nature of WebSocket. See WebSocketClientBuilder for more information.

WebSocket client example:


 WebSocketClient client = WebSocketClient.of("ws://www.example.com");
 client.connect("/chat").thenAccept(webSocketSession -> {
     // Write messages to the server.
     WebSocketWriter writer = WebSocket.streaming();
     webSocketSessions.setOutbound(writer);
     outbound.write("Hello ");
     // You can also use backpressure using whenConsumed().
     outbound.whenConsumed().thenRun(() -> outbound.write("world!"));

     // Read messages from the server.
     Subscriber<WebSocketFrame> myWebSocketSubscriber = new Subscriber<WebSocketFrame>() {
         @Override
         public void onSubscribe(Subscription s) {
             s.request(Long.MAX_VALUE);
         }
         @Override
         public void onNext(WebSocketFrame webSocketFrame) {
             if (webSocketFrame.type() == WebSocketFrameType.TEXT) {
                 System.out.println(webSocketFrame.text());
             }
             ...
         }
         ...
     };
     webSocketSessions.inbound().subscribe(myWebSocketSubscriber);
 });
 
See Also: