我一直在研究NSStreamDelegate
,我已经实现了回调,我已经初始化了输入和输出流,就像这样......
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStringRef host = CFSTR("74.125.224.72");
UInt32 port = 2270;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, port, &inputStream, &writeStream);
if (writeStream && inputStream) {
inputStream = (__bridge NSInputStream *)readStream;
[inputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
outputStream = (__bridge NSOutputStream *)writeStream;
[outputStream setDelegate:self];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream open];
}
即使在打开两个流之后,callback(stream:(NSStream *)theStream handleEvent:)
也不会NSStreamEventOpenCompleted
为两个流调用流。谁能帮助我我在这里做错了什么。或者什么是NSStreamEventOpenCompleted
不会被调用的可能性,我在文档中看到,如果打开失败它不会调用这个,如果是这样,为什么打开流失败。任何想法?
谢谢你的帮助。