最有效的方式做网络在Mac / iPhone? [英] Most effective way to do networking on Mac/iPhone?

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

问题描述

在Mac和iPhone上建立TCP连接或发送UDP数据报是最有效的方式(即最佳工作率与可读性和可维护性的比率)?我对于经典的BSD套接字很熟悉,但我现在不是为了便携性;我只是想快速完成一个小项目。



我想有一个苹果提供的Objective-C包装,但我想听到一些关于人们通常做什么的想法。如果你认为BSD套接字是走的路,也可以尝试一些想法:我真的只是想找到正确的方式做。



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






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



但是,我当前的应用程序是什么让我问的问题;我想知道人们通常做什么。当我最后一次认真工作与VB6大约7-8年前,WinSock ActiveX控件做的事情有点不同的是做BSD套接字,不管它做了什么。

解决方案

对于网络,简单的答案是



(1)ASIHttpRequest ........ 注意 - 此质量检查非常旧。不幸的是,ASIHttpRequest只有历史意义,不再可用。



(2)AsyncSocket



(3)当你开始... GameKit可以使用它)



(4)只需使用Bonjour(两行代码)来查找其他设备即可。



一个苹果提供的Objective-C包装器... AsyncSockets(最初由神秘的Dustin J.Voss写的) 是SO GOOD,苹果公司不会费心尝试写一个



AsyncSockets正是你所期待的。它在30万个iFone应用程序中随处可用。它是iFone上的网络。希望它有所帮助。



注意 - 此质量检查非常旧。你现在可以很容易地找到现代版本的软件,如AsyncSockets。



BTW,这是毫无价值的,绝对没有错 - 只是使用GK ..性能可以壮观。关于唯一的缺点是配对简单地需要一个很长的时间与GK。这是一个幼稚的混乱为十岁的学生编程创建。你将能够做直接与AsyncSockets工作100倍更快的配对。



你可能喜欢使用一些玩具GK代码,而你找出了Bonjour和所有。 p>

我建议的意见的共识是,没有点工作在更低的水平(即原始套接字)比AsyncSocket ..没有太多的性能



注意 - 如果您刚刚接触gamekit / iOS,请务必阅读这个重要提示!

Client/Server GKSessions



希望它有帮助。


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.

解决方案

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.

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

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