问题描述
如何在wss中使用netty websocket客户端?
How can use netty websocket client with wss?
现在我需要一个websocket客户端,我找到一个websocket示例( https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/http/websocketx /client/WebSocketClient.java ),但它仅支持ws.谁可以提供一个支持wss的websocket客户端示例?
Now I need one websocket client, I find one websocket example (https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java) in netty , but it only support ws. Who could provide one websocket client example which support wss?
谁可以帮助我?
谢谢
乔斯
谢谢
我现在将SslHandler作为ChannelPipeline中的第一个处理程序
I put the SslHandler as the first hander in the ChannelPipeline now
SSLEngine sslEngine = SSLContextProvider.get().createSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(sslEngine));
然后运行示例中的WebSocketClient将一台Websocket服务器与wss连接,得到一个错误:
Then run the WebSocketClient in example to connect one websocket server with wss, get one error:
WebSocket Client sending message
java.lang.ClassCastException: io.netty.handler.codec.http.websocketx.TextWebSocketFrame cannot be cast to io.netty.buffer.ByteBuf
at io.netty.handler.ssl.SslHandler.write(SslHandler.java:389)
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite0(DefaultChannelHandlerContext.java:716)
at io.netty.channel.DefaultChannelHandlerContext.access$26(DefaultChannelHandlerContext.java:713)
at io.netty.channel.DefaultChannelHandlerContext$18.run(DefaultChannelHandlerContext.java:705)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:353)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:365)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Unknown Source)
如何解决?
推荐答案
只需将SslHandler作为ChannelPipeline中的第一个处理程序.就是这样.
Just put the SslHandler as the first hander in the ChannelPipeline. That's all.
这篇关于netty websocket客户端如何与wss一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!