2011-05-31 54 views
0

誰能告訴我istream和ostream的的funcion下面的代碼,我怎麼可以聲明istream和ostream的,因爲我HV淨米沒有關於代碼iphone功能

多的知識挑碼
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]; 
    /* ... */ 
} 

回答

0

根據NSStream reference page,iStream應該是NSInputStream*指針,而oStream應該是NSOutputStream*&表示您將iStreamoStream的地址傳遞給-getStreamsToHost:...方法。這就是你在C(或Objective-C)中通過引用傳遞的方式。然後,該方法將嘗試打開與指定主機的連接,如果成功,則會爲數據流創建流對象(iStream)和來自(oStream)的主機,並將它們返回到這些變量中。