2

CFStreamCreateBoundPair is writing 4kb data to stream and stream will parser the data which contains start node of xml and it doesnt contain end node.how to write the code and manage the code so that we are writing correct xml data to nsoutputstream.

CFStreamCreateBoundPair(NULL, (CFReadStreamRef *)&iStream, (CFWriteStreamRef *)&oStream,4096);

  • Are you, per chance, on iOS prior to version 5.0? If so, the comment near `CFStreamCreateBoundPairCompat()` at this url might be of interest: http://developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Listings/PostController_m.html – ipmcc Feb 06 '13 at 13:53
  • in the code given by apple doesnt contain managing xml nodes. – user2031994 Feb 06 '13 at 14:02
  • That's irrelevant. CFStreams don't care about XML. It's all "bytes" to them. I took a stab at answering your question. Hopefully it helps. – ipmcc Feb 06 '13 at 14:03
  • I tried the same code.It is still giving start node and some data but i didnt get end node.How to fix this issue?There will be good appreciation if anyone can fix this issue. – user2031994 Feb 06 '13 at 14:09

1 Answers1

2

The bound stream pair works such that you can write in chunks into the write stream and something else can read in chunks from the read stream. You've set transferBufferSize to 4096 here. This indicates that the data will be moved from the write stream to the read stream in chunks of 4096 bytes (4K). If your source data is >4K but <8K in length, that would explain why you're only getting the first 4K of it. If, say, your data is 6K long, then the first 4K will be sent to the read stream, then the next 2K will be queued up, but my understanding is that it will sit waiting in a buffer until one of two things happen:

  1. Enough data arrives to complete a second 4K block.
  2. The write stream is closed.

So if 6K is all you're ever going to write to the write stream, then you need to close the write stream with CFWriteStreamClose(oStream); in order for the last 2K to be sent to the read stream. Otherwise, my expectation would be that it would just sit there forever.

ipmcc
  • 29,581
  • 5
  • 84
  • 147
  • I am writing to o/p stream in do while loop.. thats what you are saying? – user2031994 Feb 06 '13 at 14:15
  • 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) i will write to stream – user2031994 Feb 06 '13 at 14:18
  • stream:(NSStream *)s handleEvent: hasspaceavailable is also calling writetostream method – user2031994 Feb 06 '13 at 14:21
  • I think you misunderstood the question.I have all the server data saved into nsmutabledata.but i am writing only 4kb of data to stream. – user2031994 Feb 06 '13 at 14:28
  • You cant work with CFStreams in a do/while loop like this. They rely on the run loop to be running, which it won't be as long as you're in your do/while loop. Also, if you have all the data in memory already, just write it all to the stream in a single call; At that point there's little advantage to trying to chunk it. You should probably read up on CFStreams, NSRunLoops and how they work together. – ipmcc Feb 06 '13 at 15:19
  • I am writing 32768 bytes to stream.I am getting correct response.yestserday I fixed it.Thanks for help. – user2031994 Feb 07 '13 at 04:41