macos CFNetwork 和 Bonjour 集成,用于 iPhone 到 Mac 的集成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3240617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:03:49  来源:igfitidea点击:

CFNetwork and Bonjour integration for iPhone to Mac integration

iphoneobjective-cmacosbonjourcfnetwork

提问by objectiveccoder001

I want to use CFNetwork and Bonjour in conjunction to be able to have communications between my iPhone app and a Mac app. The app on the iPhone would have one button. Then on the Mac app, there will be a label. If the button is pushed on the iPhone app, the label changes on the Mac app.

我想结合使用 CFNetwork 和 Bonjour 以便能够在我的 iPhone 应用程序和 Mac 应用程序之间进行通信。iPhone 上的应用程序只有一个按钮。然后在 Mac 应用程序上,会有一个标签。如果在 iPhone 应用程序上按下按钮,则 Mac 应用程序上的标签会发生变化。

Is there example code out there that can do this? If not, can someone lead me in the right direction?

有没有可以做到这一点的示例代码?如果没有,有人可以引导我走向正确的方向吗?

Thanks!

谢谢!

回答by Brad Larson

Bill Dudney created a sample iPhone Bonjour applicationto demonstrate how to use Bonjour to discover and connect to two iPhones. I ported this example to the Macto demonstrate how to do Bonjour discovery between the two platforms. Bill also provides a nice writeupof how he put together the Bonjour wrapper used in this example.

Bill Dudney 创建了一个示例 iPhone Bonjour 应用程序来演示如何使用 Bonjour 发现并连接到两部 iPhone。我将此示例移植到 Mac 上,以演示如何在两个平台之间进行 Bonjour 发现。Bill 还提供了一篇关于他如何组合本示例中使用的 Bonjour 包装器的精彩文章。

This is a very simple example, and with the Mac and iPhone clients it does something similar to what you want. Only minor modifications should be needed.

这是一个非常简单的示例,对于 Mac 和 iPhone 客户端,它可以执行类似于您想要的操作。只需要进行微小的修改。

I show this in action in the video for the Networking session of my Advanced iPhone Development course on iTunes U.

在 iTunes U 上的高级 iPhone 开发课程的网络会话视频中展示了这一点。

回答by Boobalan

Here i have created some simple sample application which exchange the data between iPhone and iMAC.

在这里,我创建了一些简单的示例应用程序,用于在 iPhone 和 iMAC 之间交换数据。

https://github.com/boobalaninfo/Bonjour-iOS-MAC-Apps

https://github.com/boobalaninfo/Bonjour-iOS-MAC-Apps