开发者

iphone function of istream and ostream

can anyone tell me the funcion of istream and ostream in the following code and how can i declare istream and ostream as i hv picked the code from net m not having much knowledge about the code

NSString *urlStr = @"192.168.178.26";
if (![urlStr isEqualToString:@""]) {
    NSURL *website = [NSURL URLWithString:urlStr];
    if (!website) {
        NSLog(@"%@ is not a valid URL");
        return;
    }
    NSHost *host = [NSHost hostWithName:[website host]];
    [NSStream getStreamsToHost:host port:3258 开发者_开发百科inputStream:&iStream  outputStream:&oStream];
    [iStream retain];
    [oStream retain];
    [iStream setDelegate:self];
    [oStream setDelegate:self];
    [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [iStream open];
    [oStream open];
    /* ... */
}


According to the NSStream reference page, iStream should be an NSInputStream* pointer and oStream should be an NSOutputStream*. The & means that you're passing the addresses of iStream and oStream into the -getStreamsToHost:... method. This is how you pass by reference in C (or Objective-C). That method will then try to open a connection to the host you specified, and if successful will create stream objects for data streams to (iStream) and from (oStream) that host and will return them in those variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜