I want to send image through iOS devices by BSD Socket.
As we know, an image is divided into several packages to be sent out, So the receiver needs the size of the image.
So I want to insert the size to the beginning of the images’s binary data.
NSData* image = UIImagePNGRepresentation(screenShot);
NSUInteger len = [image length];
NSMutableData *header = [[NSMutableData alloc] initWithBytes:&len length:sizeof(NSUInteger)];
[header appendData:msg];
Receiver get the NSData and parse
NSUInteger len;
[header getBytes:&len length:sizeof(NSUInteger)]
I tried to insert int, char and NSString, but I never get the right number of the size. What’s wrong with my solution?
Are there better ones?
I finally solved the problem with iOS NSData+Base64 Category http://projectswithlove.com/projects/NSData_Base64.zip