【问题标题】:bad access exc_i386_gpflt on CFStreamCreatePairWithSocketToHostCFStreamCreatePairWithSocketToHost 上的错误访问 exc_i386_gpflt
【发布时间】:2015-04-02 13:40:25
【问题描述】:

我正在尝试与我的服务器建立 TLS 连接,但它出错了

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, str, 5555, &readStream, &writeStream); 

exc_i386_gpflt 访问不正确。我该如何解决?

完整代码

CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStringRef str = (CFStringRef)"127.0.0.1";
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, str, 5555, &readStream, &writeStream);
if (readStream && writeStream) {
    CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

    NSInputStream *inputStream = (__bridge NSInputStream *)readStream;
    [inputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];

    NSOutputStream *outputStream = (__bridge NSOutputStream *)writeStream;
    [outputStream setDelegate:self];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream open];
}

if (readStream)
    CFRelease(readStream);

if (writeStream)
    CFRelease(writeStream);

【问题讨论】:

    标签: ios objective-c sockets ssl exc-bad-access


    【解决方案1】:

    试试这个:

    CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)HOST, PORT, &readStream, &writeStream);
    

    【讨论】:

    • 我需要在 5555 端口上连接到 127.0.0.1,我应该写什么而不是 (__bridge CFStringRef)HOST?
    • 我试试这个CFStringRef str = (CFStringRef)"127.0.0.1"; CFHostRef host = CFHostCreateWithName(kCFAllocatorDefault, str);,但现在主机出现同样的错误。
    • const NSInteger PORT = 5555; const NSString * HOST = @"127.0.0.1"; CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)HOST, PORT, &readStream, &writeStream);
    猜你喜欢
    • 1970-01-01
    • 2015-12-24
    • 2013-08-13
    • 2014-10-16
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多