How to write data to stream until all the data coming from server is written to NSOutputstream

StackOverflow https://stackoverflow.com/questions/14706383

  •  06-03-2022
  •  | 
  •  

문제

How to write data to stream continuously and parse the stream until all the data coming from server is written to NSOutputstream

      NSLog(@"Response %@",[[NSString alloc] initWithData:self.m_cWebData encoding:NSUTF8StringEncoding]);
     NSUInteger written = [oStream write:(const uint8_t *)[self.m_cWebData bytes] maxLength:[self.m_cWebData length]];
     NSLog(@"Rcvd Data=%d written = %d",[self.m_cWebData length],written);
     [self.m_cWebData replaceBytesInRange:NSMakeRange(0,written) withBytes:"" length:0];
     NSLog(@"Rcvd Data after Reset =%d ",[self.m_cWebData length]);

And also I am starting parsing.but Stream:handleEvent is not getting called for the stream events.How to write the data to stream if total server response data is not taken by stream and there is some more data to be written to stream.How to handle this case.

도움이 되었습니까?

해결책

do {
    bytesWritten = [oStream write:(const uint8_t *)[self.m_cWebData bytes] maxLength:dataLength - bytesWrittenSoFar];

    NSLog(@"Rcvd Data=%d written = %d",[self.m_cWebData length],bytesWritten);
    [self.m_cWebData replaceBytesInRange:NSMakeRange(0,bytesWritten) withBytes:"" length:0];

    NSLog(@"Rcvd Data after Reset =%d ",[self.m_cWebData length]);
    assert(bytesWritten != 0);
    if (bytesWritten == -1) {

    } else {
       bytesWrittenSoFar += bytesWritten;
    }
} while (bytesWrittenSoFar != dataLength);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top