在 Mac/iPhone 上进行联网的最有效方法? [英] Most effective way to do networking on Mac/iPhone?

查看:28
本文介绍了在 Mac/iPhone 上进行联网的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mac 和 iPhone 上建立 TCP 连接或发送 UDP 数据报的最有效方法是什么(即工作量与可读性和可维护性的最佳比率)?我对经典的 BSD 套接字非常熟悉,但我现在的目标不是可移植性;我只是想快速完成一个小项目.

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.

我很想拥有一个 Apple 提供的 Objective-C 包装器,但我想听听关于人们通常在做什么的一些想法.如果您认为 BSD 套接字是要走的路,也请随意提出一些想法:我真的只是想找到正确的方法"来做到这一点.

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.

让我们假设协议是一个自定义协议,所以我们的需求不能由基于 Cocoa 的 HTTP 客户端类提供服务:)

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

我目前的目标是通过 UDP 通过网络流式传输设备状态(例如加速度计),同时还通过 TCP 保持信令和交付保证事件(例如按下按钮)连接.桌面应用程序将显示此状态.

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.

然而,我目前的申请正是让我提出这个问题的原因;我想知道人们通常会做什么.大约 7 到 8 年前,当我上一次认真使用 VB6 时,WinSock ActiveX 控件所做的事情与使用 BSD 套接字所做的事情有些不同,无论它在幕后做了什么.

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.

推荐答案

对于网络,简单的答案是,

For networking, the simple answer is,

(1) ASIHttpRequest ........ 注意 - 这个 QA 已经很老了.不幸的是, ASIHttpRequest 仅具有历史意义,不再可用.

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

(2) 异步套接字

(3) 当你刚开始时...... GameKit(孩子可以使用它)

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

(4) 只需使用 Bonjour(两行代码)即可找到其他设备.

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

Apple 提供的 Objective-C 包装器"...... AsyncSockets(最初由神秘的 Dustin J. Voss 编写)非常好,Apple 不会费心去写一个em>!

"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 正是您所追求的.它在 300,000 个 iFone 应用程序中无处不在.它是"iFone 上的网络.希望有帮助.

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.

再次说明 - 这个 QA 已经很老了.您现在可以轻松找到 AsyncSockets 等软件的现代版本".

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

顺便说一句,完全没有错——完全没有错——仅仅使用 GK .. 性能可以是壮观的,这是毫无价值的.唯一的缺点是与 GK 配对需要很长时间.这是为 10 岁的孩子学习编程创造的幼稚混乱.您将能够直接使用 AsyncSockets 将配对速度提高 100 倍.

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.

您可能更喜欢使用一些玩具 GK 代码,同时您还可以找出 Bonjour 之类的东西.

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

我建议大家的共识是,在比 AsyncSocket 更低的级别(即原始套接字)上工作是没有意义的......那里没有更多的性能.

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.

注意 - 如果您不熟悉游戏套件/iOS,请务必阅读此重要提示!
客户端/服务器 GKSessions

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

希望能帮到你.

这篇关于在 Mac/iPhone 上进行联网的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆