在CFStreamCreatePairWithSocketToHost上访问错误的exc_i386_gpflt

时间:2015-02-03 11:15:57

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

我试图与我的服务器建立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);

1 个答案:

答案 0 :(得分:1)

试试这个:

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