Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

cocoa - Most effective way to do networking on Mac/iPhone?

What would be the most effective way (that is, best ratio of effort vs readability and maintainability) to establish TCP connection or send UDP datagrams on Mac and iPhone? I'm very familiar with classic BSD sockets, but I'm not aiming for portability right now; I'm just trying to be quickly done with a small project.

I'd love to have an Apple-provided Objective-C wrapper, but I'd like to hear some thoughts on what people are commonly doing. If you think BSD sockets are the way to go, feel free to punch in some thoughts, too: I'm really just interested in finding the "right way" to do it.

Let's presume the protocol to be a custom one, so our needs cannot be serviced by the Cocoa-based HTTP client classes :)


My current aim is to stream device status (e.g. accelerometer) over the network over UDP while also maintaining signaling and delivery-guaranteed-event (e.g. button pressed) connection over TCP. A desktop application would display this status.

However, my current application is just what made me ask the question; I'm wondering what people generally do. When I last seriously worked with VB6 about 7-8 years ago, WinSock ActiveX control did things a bit different than what is done with BSD sockets, no matter what it did under the hood.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...