我是Objective-C的新手。 我试图创建一个与服务器通信的客户端。 在流设置之后,我看到NSOutputStream的事件(NSStreamEventOpenCompleted& NSStreamEventHasSpaceAvailable),但NSInputStream没有。 它可以将数据发送到服务器,也可以通过直接读取到NSInputStream来从服务器读取数据。但是,InputStream的事件从未触发过。
以下是Stream设置代码:
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, CFBridgingRetain(IP), port, &readStream, &writeStream);
_rStream = (__bridge_transfer NSInputStream *)readStream;
_wStream = (__bridge_transfer NSOutputStream *)writeStream;
[_rStream setDelegate:self];
[_wStream setDelegate:self];
[_rStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_wStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_rStream open];
[_wStream open];
有什么问题吗?