netty websocket客户端如何与wss一起使用? [英] How can use netty websocket client with wss?

查看:1831
本文介绍了netty websocket客户端如何与wss一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在wss中使用netty websocket客户端?

How can use netty websocket client with wss?

现在我需要一个websocket客户端,我找到一个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一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆