我正在尝试创建Bonjour客户端,并且在尝试设置输入和输出流的过程中,我已经成功创建了bonjour客户端,检测到并解决了它们。在解决之后,我正在尝试设置输入和输出流,但是当我尝试发送消息时,他们不会去。流代理也没有被调用,当我检查流状态它总是1(即打开),但永远不会改变为打开。 以下是我为获取流而采取的措施:
-(void)viewDidAppear:(BOOL)animated
{
[self.service getInputStream:&inputStream outputStream:&outputStream];
if(inputStream && outputStream)
{
[outputStream setDelegate:self];
[inputStream setDelegate:self];
[self scheduleInCurrentThread];
[inputStream open];
[outputStream open];
NSLog(@"%lu",(unsigned long)inputStream.streamStatus);
NSLog(@"got Streams");
}
else
{
NSLog(@"failed to acquire streams");
}
}
#pragma mark - schedule in current thread
- (void)scheduleInCurrentThread
{
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
}
P.S:没有任何对象是nill。