简体   繁体   English

在iPhone和macbook笔记本电脑之间进行通信

[英]Communicate between iPhone and macbook laptop

In an effort to learn more about networking I'd like to do an exercise: write some code on an iPhone and macbook laptop that allows the devices to communicate over HTTP. 为了更多地了解网络,我想做一些练习:在iPhone和macbook笔记本上写一些代码,允许设备通过HTTP进行通信。

How would I set this up in general? 我一般如何设置它? I could write a very simple web server as illustrated in Beej's Guide . 我可以编写一个非常简单的Web服务器,如Beej指南中所示 Then run this and make requests from the phone. 然后运行此命令并从手机发出请求。 Assume the two devices will be on the same wifi network. 假设两个设备将在同一个wifi网络上。

In this book you can find an example of how to make a network to connect a Mac OS X app with an iOS app using Bonjour. 在本书中,您可以找到如何使用Bonjour建立网络以将Mac OS X应用程序与iOS应用程序连接的示例。

http://my.safaribooksonline.com/book/programming/mobile/9780132757058/bonjour-and-web-servers/ch28 http://my.safaribooksonline.com/book/programming/mobile/9780132757058/bonjour-and-web-servers/ch28

Hope this helps you. 希望这对你有所帮助。

Using HTTP between two apps is very inefficient. 在两个应用程序之间使用HTTP效率非常低。 Use NSNetService and raw sockets. 使用NSNetService和原始套接字。

NSNetService Docs NSNetService文档

There is an example project that shows how to setup the service for publishing, connect 2 services, and consume data from a socket connection. 有一个示例项目显示如何设置服务以进行发布,连接2个服务以及使用套接字连接中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM