Socket Communication in iPhone

Posted by Timmi on Stack Overflow See other posts from Stack Overflow or by Timmi
Published on 2010-04-08T13:25:06Z Indexed on 2010/04/10 11:43 UTC
Read the original article Hit count: 342

Filed under:

I have many images in iPhone. I have to send this images to server using a socket communication. what all we need to do to send the images to server through socket.

If i use this code i can send string. what all should i change in the code so that i can send image through socket. I am new to network programming so some please help me to find a solution

CFWriteStreamRef writeStream = NULL;

CFStringRef host = CFSTR("192.168.1.211"); UInt32 port = 8001;

CFStreamCreatePairWithSocketToHost(kCFAllocatorDef ault, host, port, NULL, &writeStream);

CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

if(!CFWriteStreamOpen(writeStream)) { NSLog(@"Error Opening Socket"); } else{ UInt8 buf[] = "Hi !!!";

int bytesWritten = CFWriteStreamWrite(writeStream, buf, strlen((char*)buf)); NSLog(@"Written: %d", bytesWritten);

if (bytesWritten < 0) { CFStreamError error = CFWriteStreamGetError(writeStream);

}

}

Thanks,

© Stack Overflow or respective owner

Related posts about iphone