use of io.crossbar.autobahn.wamp.types.TransportOptions in project autobahn-java by crossbario.
the class Client method connect.
public CompletableFuture<ExitInfo> connect(TransportOptions options) {
CompletableFuture<ExitInfo> exitFuture = new CompletableFuture<>();
mSession.addOnConnectListener((session) -> mSession.join(mRealm, mAuthenticators).thenAccept(details -> LOGGER.i(String.format("JOINED session=%s realm=%s", details.sessionID, details.realm))));
mSession.addOnDisconnectListener((session, wasClean) -> exitFuture.complete(new ExitInfo(wasClean)));
CompletableFuture.runAsync(() -> {
try {
mTransports.get(0).connect(mSession, options);
} catch (Exception e) {
throw new CompletionException(e);
}
}, getExecutor());
return exitFuture;
}
use of io.crossbar.autobahn.wamp.types.TransportOptions in project autobahn-java by crossbario.
the class NettyWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
if (options == null) {
if (mOptions == null) {
options = new TransportOptions();
} else {
options = new TransportOptions();
options.setAutoPingInterval(mOptions.getAutoPingInterval());
options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
}
}
URI uri;
uri = new URI(mUri);
int port = validateURIAndGetPort(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
final SslContext sslContext = getSSLContext(scheme);
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
TransportOptions opt = options;
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
if (sslContext != null) {
channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
}
channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
}
});
mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
mHandler.getHandshakeFuture().sync();
}
Aggregations