gpt4 book ai didi

iphone - CFStream SSL 错误 -9800

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


我的 iOS 应用程序包含 2 个版本:服务器和客户端。服务器通过 Bonjour 发布服务并等待客户端。客户端搜索该服务并连接到服务器。之后所有的通信都是通过 CFSockets 实现的。
这是我为此类通信设置流的代码:

- (BOOL)setupSocketStreams {
if ( readStream == nil || writeStream == nil ) {
return NO;
}
incomingDataBuffer = [[NSMutableData alloc] init];
outgoingDataBuffer = [[NSMutableData alloc] init];

// Turning SSL on
NSDictionary *sslSettings = [NSDictionary dictionaryWithObjectsAndKeys:(id)kCFBooleanFalse, (id)kCFStreamSSLValidatesCertificateChain, nil];
CFReadStreamSetProperty(readStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelNegotiatedSSL);
CFReadStreamSetProperty(readStream, kCFStreamPropertySSLSettings, sslSettings);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelNegotiatedSSL);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertySSLSettings, sslSettings);

CFReadStreamSetProperty(
readStream,
kCFStreamPropertyShouldCloseNativeSocket,
kCFBooleanTrue
);
CFWriteStreamSetProperty(
writeStream,
kCFStreamPropertyShouldCloseNativeSocket,
kCFBooleanTrue
);

CFOptionFlags registeredEvents =
kCFStreamEventOpenCompleted |
kCFStreamEventHasBytesAvailable |
kCFStreamEventCanAcceptBytes |
kCFStreamEventEndEncountered |
kCFStreamEventErrorOccurred
;

CFStreamClientContext ctx = {
0, // version
self, // info
NULL, // retain callback
NULL, // release callback
NULL // copyDescription callback
};

CFReadStreamSetClient(
readStream,
registeredEvents,
readStreamEventHandler,
&ctx
);
CFWriteStreamSetClient(
writeStream,
registeredEvents,
writeStreamEventHandler,
&ctx
);

CFReadStreamScheduleWithRunLoop(
readStream,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes
);
CFWriteStreamScheduleWithRunLoop(
writeStream,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes
);

if ( ! CFReadStreamOpen(readStream) || ! CFWriteStreamOpen(writeStream)) {
[self close];
return NO;
}

if ([self.delegate respondsToSelector:@selector(establishedConnection:)]) {
[self.delegate establishedConnection:self];
}

return YES;
}

没有在这段代码上启用 SSL 的部分工作正常,但除此之外我收到错误:

Error:
The operation couldn’t be completed. (OSStatus error -9800.)

会是什么问题?
谢谢!

最佳答案

iOS 5 中的 TLS1.2 支持存在一个已知问题:https://developer.apple.com/library/ios/#technotes/tn2287/_index.html#//apple_ref/doc/uid/DTS40011309

通过将 kCFStreamSSLLevel 设置为 @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3",我能够修复我的应用程序中的 -9800 问题。

关于iphone - CFStream SSL 错误 -9800,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10276217/

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