Open mprimeaux opened 12 years ago
Tried the stream methods, addDownloadStream?
Sent from my iPhone Mugunth Kumar Author | Developer | Trainer iOS 5 Programming book iBooks: http://mk.sg/ibook Amazon: http://mk.sg/ios5book
On 7 Oct, 2012, at 10:39 PM, Michael Primeaux notifications@github.com wrote:
Is there a recommended method for leveraging MKNetworkKit for HTTP streaming over persistent connections? For example, streaming from Twitter. The existing documentation, posts, and examples illustrate streaming of files\ over HTTP.
Any insight is appreciated.
Kindest Regards, Michael
— Reply to this email directly or view it on GitHubhttps://github.com/MugunthKumar/MKNetworkKit/issues/207.
Thanks for your prompt reply. I did see that method but perhaps dismissed using it prematurely. Do you suggest using the NSOutputStream class method +outputStreamToMemory and then simply leverage propertyForKey passing in NSStreamDataWrittenToMemoryStreamKey?
Again, thanks for any insight.
That should work, though I haven't tried.
Sent from my iPhone Mugunth Kumar Author | Developer | Trainer iOS 5 Programming book iBooks: http://mk.sg/ibook Amazon: http://mk.sg/ios5book
On 7 Oct, 2012, at 10:52 PM, Michael Primeaux notifications@github.com wrote:
Thanks for your prompt reply. I did see that method but perhaps dismissed using it prematurely. Do you suggest using the NSOutputStream class method +outputStreamToMemory and then simply leverage propertyForKey passing in NSStreamDataWrittenToMemoryStreamKey?
Again, thanks for any insight.
— Reply to this email directly or view it on GitHubhttps://github.com/MugunthKumar/MKNetworkKit/issues/207#issuecomment-9208684.
I just wanted to provide an update.
Unfortunately, I am unable to get MKNetworkKit to work for data streams that, essentially, never complete. For example, a Twitter stream. Let's, of course, discount Byzantine failures. The challenge is that MKNetworkOperation does not seem to be designed for this scenario. Of course, I may be missing something important, and, pointers (no pun intended) are appreciated.
Using the method described in my previous reply and, based on the current API shape, MKNetworkKIt does not allow me to receive the data within MKNetworkOperation's...
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
...and so I am not able to receive notification as data is received until the operation completes.I'll work on a few options and post for comment. Please keep in mind that I am not downloading a file.
As always, I do appreciate your time.
In the same method, connection:didReceiveData:
if([self.downloadStreams count] == 0) [self.mutableData appendData:data];
for(NSOutputStream *stream in self.downloadStreams) {
if ([stream hasSpaceAvailable]) {
const uint8_t *dataBuffer = [data bytes];
[stream write:&dataBuffer[0] maxLength:[data length]];
}
}
The downloadStreams are written to if one is attached. If no downloadStream is present, you get the complete operation after it completes.
Mugunth Author | Developer | Trainer iostraining.sg Preorder the iOS 6 Programming Pushing the Limits book http://mk.sg/ios6book
On 20 Oct, 2012, at 8:33 AM, Michael Primeaux notifications@github.com wrote:
I just wanted to provide an update.
Unfortunately, I am unable to get MKNetworkKit to work for data streams that, essentially, never complete. For example, a Twitter stream. Let's, of course, discount Byzantine failures. The challenge is the MKNetworkOperation does not seem to be designed for this scenario. Of course, I may be missing something important, and, pointers (no pun intended) are appreciated.
Using the method described in my previous reply and, based on the current API shape, MKNetworkKIt does not allow me to receive the data within MKNetworkOperation's...
- (void)connection:(NSURLConnection )connection didReceiveData:(NSData )data; ...and so I am not able to receive notification as data is received until the operation completes.I'll work on a few options and post for comment.
As always, I do appreciate your time.
— Reply to this email directly or view it on GitHub.
Yes. Of course that is true. However, I have added NSOutputStream class method +outputStreamToMemory as a downloadStream but, even after setting the NSOutputStream delegate property, does not receive stream events when the stream was written to. The issue is the NSOutputStream:write does not call my delegate when written to and so I am unable to receive any events other than the event code of NSStreamEventHasSpaceAvailable, which I found a bit unusual. Of course, the ideal event in my inherited MKNetworkEngine class would be NSStreamEventHasBytesAvailable. What is most interesting is that I expected the NSStreamEventHasBytesAvailable event to be called when MKNetworkOperation invoked the downloadStream's write:maxLength method, but it was not.
I encourage you to try as time permits.
Is there a recommended method for leveraging MKNetworkKit for streaming over persistent connections? For example, streaming from Twitter. The existing documentation, posts, and examples illustrate streaming of files over HTTP. I am aware I can use CFNetwork but am trying to remain one layer above.
Any insight is appreciated.
Kindest Regards, Michael