Websocket Netty WebScoketClientHandshaker不工作
我有个问题。谁能帮我?非常感谢。我想创建websocketclient,但我的代码在handShaker.handshake(ch.syncunterruptibly();。。。 websocket服务器运行良好,因为我已经使用JS对其进行了测试。只有netty客户端不工作 下面是我的代码Websocket Netty WebScoketClientHandshaker不工作,websocket,netty,Websocket,Netty,我有个问题。谁能帮我?非常感谢。我想创建websocketclient,但我的代码在handShaker.handshake(ch.syncunterruptibly();。。。 websocket服务器运行良好,因为我已经使用JS对其进行了测试。只有netty客户端不工作 下面是我的代码 public void Start() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try{
public void Start() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap b = new Bootstrap();
URI uri = new URI(url);
WebSocketClientHandshaker handShaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, null);
WebSocketClientHandler handler = new WebSocketClientHandler(handShaker, actionHandlers);
b.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(8192));
pipeline.addLast(handler);
}
});
ch = b.connect(uri.getHost(), uri.getPort()).sync().channel();
//handler.handShakeFuture().sync();
handShaker.handshake(ch).syncUninterruptibly();
ch.closeFuture().awaitUninterruptibly();
}catch(Exception e) {
e.printStackTrace();
}
}
public void Start()引发异常{
EventLoopGroup=new NioEventLoopGroup();
试一试{
引导b=新引导();
URI=新的URI(url);
WebSocketClientHandshaker handShaker=WebSocketClientHandshakerFactory.newHandshaker(uri,WebSocketVersion.V13,null,false,null);
WebSocketClientHandler handler=新的WebSocketClientHandler(握手器、ActionHandler);
b、 组(组)
.channel(NioSocketChannel.class)
.handler(新的通道初始值设定项(){
@凌驾
public void initChannel(SocketChannel ch)引发异常{
ChannelPipeline=通道管道();
addLast(新的HttpClientCodec());
addLast(新的HttpObjectAggregator(8192));
pipeline.addLast(处理程序);
}
});
ch=b.connect(uri.getHost(),uri.getPort()).sync().channel();
//handler.handShakeFuture().sync();
握手器。握手(ch)。不间断地同步();
(不间断地等待);
}捕获(例外e){
e、 printStackTrace();
}
}
没人知道?现在没人用netty?没人知道?现在没人用netty了?