0

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];
    /* ... */
}
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
Junior Bill gates
  • 1,858
  • 4
  • 20
  • 33

1 Answers1

0

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.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
Caleb
  • 124,013
  • 19
  • 183
  • 272