Most effective way to do networking on Mac/iPhone?

Solution 1:

For networking, the simple answer is,

(1) ASIHttpRequest ........ NOTE - this QA is very old. Unfortunately ASIHttpRequest is of historic interest only and is no longer available.

(2) AsyncSocket

(3) When you're starting out ... GameKit (a child can use it)

(4) Just use Bonjour (two lines of code) to find other devices.

"an Apple-provided Objective-C wrapper" ... AsyncSockets (written originally by the mysterious Dustin J. Voss) is SO GOOD that Apple just won't bother trying to write one!

AsyncSockets is exactly what you're after. It is used everywhere in the 300,000 iFone apps. It "is" networking on the iFone. Hope it helps.

AGAIN NOTE - this QA is very old. You can easily now find "modern versions of" software like AsyncSockets.

BTW, it's worth nothing that there is absolutely nothing wrong - at all - with just using GK .. the performance can be spectacular. About the only downside is that pairing simply takes a plain long time with GK. And it's a childish mess created for ten year olds learning programming. You will be able to do 100x faster pairing working directly with AsyncSockets.

You may prefer to use some toy GK code, while you figure out Bonjour and all that.

I would suggest the consensus of opinion is that there is no point working at an even lower level (ie, raw sockets) than AsyncSocket .. there's not much more performance to be had in there.

NOTE - if you are new to gamekit / iOS be sure to read this critical tip!
Client/Server GKSessions

hope it helps.

Solution 2:

Your question can't really be answered with any detail because you haven't described what you want to do. The best answer I can give is to read the introductory networking guides for Mac and iOS.

Update

I don't think there's any "easy Cocoa way" built in for UDP. I recall this discussion has come up several times on the cocoa-dev list. The cocoaasyncsocket project has been mentioned various places. It claims:

AsyncUdpSocket is a UDP/IP socket networking library that wraps CFSocket. It works almost exactly like the TCP version, but is designed specifically for UDP. This includes queued non-blocking send/receive operations, full delegate support, run-loop based, self-contained class, and support for IPv4 and IPv6.