How to pull UIImages from NSData from a socket.
        Posted  
        
            by Jus' Wondrin'
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jus' Wondrin'
        
        
        
        Published on 2010-05-11T20:32:53Z
        Indexed on 
            2010/05/11
            20:54 UTC
        
        
        Read the original article
        Hit count: 449
        
Hey all!
I'm using ASyncSocket to move some UIImages from one device over to another.
Essentially, on one device I have:
NSMutableData *data = UIImageJPEGRepresentation(image, 0.1);
if(isRunning){
    [sock writeData:data withTimeout:-1 tag:0];
}
So a new image will be added to the socket every so often (like a webcam).
Then, on the other device, I am calling:
[listenSocket readDataWithTimeout:1 tag:0];
which will respond with:
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
    [responseData appendData:data];
    [listenSocket readDataWithTimeout:1 tag:0];
}
Essentially, what I want to be able to do is have an NSTimer going which will call @selector(PullImages):
-(void) PullImages {
In here, I want to be able to pull images out of ResponseData. How do I do that? There might not be a complete image yet, there might be multiple images, there might be one and a half images!
I want to parse the NSData into each existing image!
}
Any assistance? Thanks in advance!
© Stack Overflow or respective owner