PDA

View Full Version : Best book for Objective-C networking?




dylanweber
Mar 27, 2012, 04:38 PM
I've already read "Programming in Objective-C 2.0; Second Edition" by Stephen G. Kochan, and I believe I have absorbed all the information from it.

After a while of programming with a friend of mine, we tried using online resources to begin making small little apps that would communicate with a server. Once that worked, we wanted to make our program secure using SSL. We couldn't find any information that helped, and we're stuck. Can anyone suggest an Objective C book for information on networking or CFNetwork?



chown33
Mar 27, 2012, 06:06 PM
After a while of programming with a friend of mine, we tried using online resources to begin making small little apps that would communicate with a server.
What classes or functions are you using now to do the server communication?


Once that worked, we wanted to make our program secure using SSL. We couldn't find any information that helped, and we're stuck. Can anyone suggest an Objective C book for information on networking or CFNetwork?

Did you look at this doc: URL Loading System Programming Guide (https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html%23//apple_ref/doc/uid/10000165i)

Or see these:
http://stackoverflow.com/questions/3768893/asihttprequest-https-with-ssl
http://allseeing-i.com/ASIHTTPRequest/

Depending on what you're using now, maybe all you need is to use an HTTPS url instead of an HTTP one.

robvas
Mar 27, 2012, 06:35 PM
I've already read "Programming in Objective-C 2.0; Second Edition" by Stephen G. Kochan, and I believe I have absorbed all the information from it.

After a while of programming with a friend of mine, we tried using online resources to begin making small little apps that would communicate with a server. Once that worked, we wanted to make our program secure using SSL. We couldn't find any information that helped, and we're stuck. Can anyone suggest an Objective C book for information on networking or CFNetwork?

There are two chapters on networking (and run loops) in Advanced Mac OS X programming.

You could also check out Beej's network programming guide on the web, it's free.

But you'll probably want to just use some wrapper classes. It would be hard to write an SSL implementation from scratch.

dylanweber
Mar 27, 2012, 07:00 PM
What classes or functions are you using now to do the server communication?



Did you look at this doc: URL Loading System Programming Guide (https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html%23//apple_ref/doc/uid/10000165i)

Or see these:
http://stackoverflow.com/questions/3768893/asihttprequest-https-with-ssl
http://allseeing-i.com/ASIHTTPRequest/

Depending on what you're using now, maybe all you need is to use an HTTPS url instead of an HTTP one.

I think you're implying I'm using an HTTP protocol with URLs. I am using CFNetwork sockets, HTTP and HTTPS has nothing to do with what I've been doing.

----------

There are two chapters on networking (and run loops) in Advanced Mac OS X programming.

You could also check out Beej's network programming guide on the web, it's free.

But you'll probably want to just use some wrapper classes. It would be hard to write an SSL implementation from scratch.

Is this (http://www.amazon.com/Advanced-Mac-OS-Programming-Guides/dp/0321706250) the book?

Also, I've used Beej's guide as a source many times. He never mentions any specifics on SSL.

chown33
Mar 27, 2012, 07:26 PM
I think you're implying I'm using an HTTP protocol with URLs. I am using CFNetwork sockets, HTTP and HTTPS has nothing to do with what I've been doing.

Then please explain exactly what you've been doing, so we know what the context is for your expected answer.

If you're doing low-level sockets, then you have to implement TLS yourself, or find a library that does it for you. What have you tried? What have you searched for?

For example, the search terms cfsocket tls show CocoaAsyncSocket in the first page of results. Have you looked at that?

robvas
Mar 27, 2012, 07:27 PM
Is this (http://www.amazon.com/Advanced-Mac-OS-Programming-Guides/dp/0321706250) the book?

Also, I've used Beej's guide as a source many times. He never mentions any specifics on SSL.

That is the book. You'll want to check out chapters 15 and 16. It doesn't cover SSL, however.

dylanweber
Mar 28, 2012, 09:23 PM
Then please explain exactly what you've been doing, so we know what the context is for your expected answer.

If you're doing low-level sockets, then you have to implement TLS yourself, or find a library that does it for you. What have you tried? What have you searched for?

For example, the search terms cfsocket tls show CocoaAsyncSocket in the first page of results. Have you looked at that?

Right now, I've been trying to make a server software that communicates with telnet. We had some non-SSL working examples earlier, and I can't seem to find them in my documents folder, but here is what I have now:

static void ServerAcceptCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) {
// Server *server = (__bridge Server *)info;
printf("ServerAcceptCallBack called.\n");
if (kCFSocketAcceptCallBack == type) {
// for an AcceptCallBack, the data parameter is a pointer to a CFSocketNativeHandle
CFSocketNativeHandle nativeSocketHandle = *(CFSocketNativeHandle *)data;
uint8_t name[SOCK_MAXADDRLEN];
socklen_t namelen = sizeof(name);
NSData *peer = nil;
if (getpeername(nativeSocketHandle, (struct sockaddr *)name, &namelen) == 0) {
peer = [NSData dataWithBytes:name length:namelen];
}
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStreamCreatePairWithSocket(kCFAllocatorDefault, nativeSocketHandle, &readStream, &writeStream);
if (readStream && writeStream) {
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
SocketThread *thread = [[SocketThread alloc] init];
[thread setupSocketwithReadStream:readStream andwithWriteStream:writeStream];
} else {
close(nativeSocketHandle);
}
if (readStream) CFRelease(readStream);
if (writeStream) CFRelease(writeStream);
}
}

@implementation Server

-(BOOL)setupServer:(int)port {
CFSocketContext socketCtxt = {0, (__bridge void *)self, NULL, NULL, NULL};
CFSocketRef socket = CFSocketCreate(kCFAllocatorDefault, PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack)&ServerAcceptCallBack, &socketCtxt);
printf("Initiating Server Setup...\n");
if (socket == NULL) {
if (socket) CFRelease(socket);
socket = NULL;
return NO;
}

int yes = 1;
setsockopt(CFSocketGetNative(socket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));

struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];

if (CFSocketSetAddress(socket, (__bridge CFDataRef)address) != kCFSocketSuccess) {
if (socket) CFRelease(socket);
socket = NULL;
return NO;
}
printf("Server SHOULD be setup...\n");
return YES;
}

@end