gpt4 book ai didi

android - Android 上未调用 SslHandler.handshake() 的 ChannelFutureListener.operationComplete

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:47 25 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 netty-3.6.6 SSL。 handshake() 实际上已经完成(Android 应用程序能够向/从 SSL 服务器发送/接收数据)但是 operationComplete 永远不会被调用。我需要调用它来执行一些任务。

我错过或做错了什么吗?谢谢。

以下是设置和代码段。

@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pip = Channels.pipeline();
SSLEngine engine = SslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
SslHandler sslHandler = new SslHandler(engine);
sslHandler.setIssueHandshake(false);
pip.addLast("ssl", sslHandler);
...
return pip;
}

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
System.out.println("channelConnected");
SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
if (sslHandler != null) {
// Begin handshake.
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {

if (!future.isSuccess()) {
System.out.println("handshake failed(" + future.getCause() + ")");
} else {
System.out.println("handshake OK");
}
}
});
}
}

}

最佳答案

netty 可能无法处理返回到我正确调用 SslHandler.handshake() 的应用程序的 ChannelFuture 状态。我将 hsFuture.setSuccess() 添加到 SslHandler.handshake() 并调用了我的 operationComplete。

public ChannelFuture handshake() {
...
if (exception == null) { // Began handshake successfully.
try {
final ChannelFuture hsFuture = handshakeFuture;
wrapNonAppData(ctx, channel).addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
Throwable cause = future.getCause();
hsFuture.setFailure(cause);

fireExceptionCaught(ctx, cause);
if (closeOnSSLException) {
Channels.close(ctx, future(channel));
}
} else {
hsFuture.setSuccess();
}
}
});
} catch (SSLException e) {

关于android - Android 上未调用 SslHandler.handshake() 的 ChannelFutureListener.operationComplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18663061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com