我试图与我的服务器建立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);
答案 0 :(得分:1)
试试这个:
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)HOST, PORT, &readStream, &writeStream);