我正在尝试与服务器建立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);

最佳答案

尝试这个:

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

07-25 23:38