0

如何将数据连续写入流并解析流,直到来自服务器的所有数据都写入 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]);

而且我也开始解析。但是 Stream:handleEvent 没有被调用用于流事件。如果流未获取总服务器响应数据并且还有更多数据要写入流,如何将数据写入流。如何来处理这个案子。

4

1 回答 1

0
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);
于 2013-02-07T04:43:24.300 回答