//现在要在客户端连接多个 websocket 连接 Bootstrap bootstrap = new Bootstrap() .group(workGroup) .channel(NioSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(initializer); for (URI url : urls) { ChannelFuture channelFuture = bootstrap.connect(url.getHost(), getPort(url)).sync(); //market of channel String channelId = channelFuture.channel().id().asLongText(); Monitor.getStatus(channelId).setUrl(url.toString()); channelFuture.channel().closeFuture().sync(); }
//在设置websocket握手处理器时 无法获取上面的 url remoteAddress 报空指针 InetSocketAddress remoteAddress = socketChannel.remoteAddress(); URI uri = URIUtil.of(remoteAddress); WebSocketClientProtocolHandler webSocketClientProtocolHandler = new WebSocketClientProtocolHandler( WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders() ) );
哪位大佬有好的解决方案呀
Netty
channelActive的时候握手就可以了