问题
How can use netty websocket client with wss?
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?
Who can help me ?
Thanks
Jose
Thanks
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));
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)
How to fix it?
回答1:
Just put the SslHandler as the first hander in the ChannelPipeline. That's all.
回答2:
Just follow the netty websocket client example in Github Netty client example with WSS/WS
Just change the URL from ws to wss
来源:https://stackoverflow.com/questions/17082396/how-can-use-netty-websocket-client-with-wss