Interface WebSocketClient
- All Superinterfaces:
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:
-
Method Summary
Modifier and TypeMethodDescriptionstatic WebSocketClientBuilder
builder
(Scheme scheme, EndpointGroup endpointGroup) static WebSocketClientBuilder
builder
(Scheme scheme, EndpointGroup endpointGroup, String path) Returns a newWebSocketClientBuilder
created with the specifiedScheme
, theEndpointGroup
, and thepath
.static WebSocketClientBuilder
builder
(SessionProtocol protocol, EndpointGroup endpointGroup) Returns a newWebSocketClientBuilder
created with the specifiedSessionProtocol
and theEndpointGroup
.static WebSocketClientBuilder
builder
(SessionProtocol protocol, EndpointGroup endpointGroup, String path) Returns a newWebSocketClientBuilder
created with the specifiedSessionProtocol
, theEndpointGroup
, and thepath
.static WebSocketClientBuilder
Returns a newWebSocketClientBuilder
created with the specified baseuri
.static WebSocketClientBuilder
builder
(String scheme, EndpointGroup endpointGroup) static WebSocketClientBuilder
builder
(String scheme, EndpointGroup endpointGroup, String path) Returns a newWebSocketClientBuilder
created with the specifiedscheme
, theEndpointGroup
, and thepath
.static WebSocketClientBuilder
Returns a newWebSocketClientBuilder
created with the specified baseURI
.Connects to the specifiedpath
.static WebSocketClient
of()
Returns aWebSocketClient
without a base URI.static WebSocketClient
of
(Scheme scheme, EndpointGroup endpointGroup) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedScheme
using the defaultClientOptions
.static WebSocketClient
of
(Scheme scheme, EndpointGroup endpointGroup, String path) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedScheme
andpath
using the defaultClientOptions
.static WebSocketClient
of
(SessionProtocol protocol, EndpointGroup endpointGroup) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedSessionProtocol
using the defaultClientOptions
.static WebSocketClient
of
(SessionProtocol protocol, EndpointGroup endpointGroup, String path) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
andpath
using the defaultClientOptions
.static WebSocketClient
Returns a newWebSocketClient
that connects to the specifieduri
using the default options.static WebSocketClient
of
(String scheme, EndpointGroup endpointGroup) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
using the defaultClientOptions
.static WebSocketClient
of
(String scheme, EndpointGroup endpointGroup, String path) Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
andpath
using the defaultClientOptions
.static WebSocketClient
Returns a newWebSocketClient
that connects to the specifiedURI
using the default options.unwrap()
Unwraps this object and returns the object being decorated.Methods inherited from interface com.linecorp.armeria.client.ClientBuilderParams
absolutePathRef, clientType, endpointGroup, options, scheme, uri
Methods inherited from interface com.linecorp.armeria.common.util.Unwrappable
as, equalsIgnoreWrapper, unwrapAll
-
Method Details
-
of
Returns aWebSocketClient
without a base URI. -
of
Returns a newWebSocketClient
that connects to the specifieduri
using the default options. -
of
Returns a newWebSocketClient
that connects to the specifiedURI
using the default options. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
using the defaultClientOptions
. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedScheme
using the defaultClientOptions
. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedSessionProtocol
using the defaultClientOptions
. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
andpath
using the defaultClientOptions
. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedScheme
andpath
using the defaultClientOptions
. -
of
Returns a newWebSocketClient
that connects to the specifiedEndpointGroup
with the specifiedscheme
andpath
using the defaultClientOptions
. -
builder
Returns a newWebSocketClientBuilder
created with the specified baseuri
. -
builder
Returns a newWebSocketClientBuilder
created with the specified baseURI
. -
builder
-
builder
-
builder
Returns a newWebSocketClientBuilder
created with the specifiedSessionProtocol
and theEndpointGroup
. -
builder
Returns a newWebSocketClientBuilder
created with the specifiedscheme
, theEndpointGroup
, and thepath
. -
builder
Returns a newWebSocketClientBuilder
created with the specifiedScheme
, theEndpointGroup
, and thepath
. -
builder
static WebSocketClientBuilder builder(SessionProtocol protocol, EndpointGroup endpointGroup, String path) Returns a newWebSocketClientBuilder
created with the specifiedSessionProtocol
, theEndpointGroup
, and thepath
. -
connect
Connects to the specifiedpath
. -
unwrap
WebClient unwrap()Description copied from interface:Unwrappable
Unwraps this object and returns the object being decorated. If thisUnwrappable
is the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrap() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrap() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrap().unwrap() == foo;
- Specified by:
unwrap
in interfaceUnwrappable
-