如何通过wifi从iphone发送数据到应用程序,打印消息

时间:2021-11-15 22:07:57

i would like to know how to do the following:

我想知道如何做到以下几点:

step 1: how to send the following string from the iphone to a mac computer via WIFI when a user presses a button.

步骤1:当用户按下按钮时,如何通过WIFI将以下字符串从iphone发送到mac计算机。

string to be sent: "hello".

要发送的字符串:“你好”。

step2: how to receive that string with an application i would have to create. it will be very simple. it will have no interface, except it will just print out the message.

step2:如何使用我必须创建的应用程序接收该字符串。这将非常简单。它将没有接口,除了它只打印出消息。

How do i achieve something like this. I've never sent a signal over WIFI with the iphone programming. Can someone guide me please?

我如何实现这样的目标。我从未使用iphone编程通过WIFI发送信号。有人可以指导我吗?

2 个解决方案

#1


8  

I'll quote myself from a similar question:

我将引用一个类似的问题:

How can I create a small Mac app that receives data over the WiFi network from an iOS app?

如何创建一个从iOS应用程序通过WiFi网络接收数据的小型Mac应用程序?

Using the CFNetwork framework, you can use bonjour for discovery and then handle a persistent connection through native sockets for passing data back and forth.

使用CFNetwork框架,您可以使用bonjour进行发现,然后通过本机套接字处理持久连接,以便来回传递数据。

http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html

Here is an excellent tutorial to get started, its for iOS but CFNetwork is available in OS X too.

这是一个很好的入门教程,它适用于iOS,但CFNetwork也可以在OS X中使用。

http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone

#2


4  

If by "wifi", you mean "local network", this blog post has some sample code that has an iPhone app and Mac application communicating via Bonjour. It does a bit more that what you're asking for, but it's something that will get you started.

如果通过“wifi”,你的意思是“本地网络”,这篇博文有一些示例代码,其中有一个iPhone应用程序和Mac应用程序通过Bonjour进行通信。它确实比你所要求的更多,但它会让你开始。

If by "wifi", you mean "the Internet", you're going to need your own server sitting between the two devices. This is significantly more complex, but still doable, and you'll need to implement the server portion in whatever you're preferred server side technology is.

如果通过“wifi”,你的意思是“互联网”,你将需要你自己的服务器坐在两个设备之间。这要复杂得多,但仍然可行,您需要在服务器端技术的首选项中实现服务器部分。

#1


8  

I'll quote myself from a similar question:

我将引用一个类似的问题:

How can I create a small Mac app that receives data over the WiFi network from an iOS app?

如何创建一个从iOS应用程序通过WiFi网络接收数据的小型Mac应用程序?

Using the CFNetwork framework, you can use bonjour for discovery and then handle a persistent connection through native sockets for passing data back and forth.

使用CFNetwork框架,您可以使用bonjour进行发现,然后通过本机套接字处理持久连接,以便来回传递数据。

http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html

Here is an excellent tutorial to get started, its for iOS but CFNetwork is available in OS X too.

这是一个很好的入门教程,它适用于iOS,但CFNetwork也可以在OS X中使用。

http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone

#2


4  

If by "wifi", you mean "local network", this blog post has some sample code that has an iPhone app and Mac application communicating via Bonjour. It does a bit more that what you're asking for, but it's something that will get you started.

如果通过“wifi”,你的意思是“本地网络”,这篇博文有一些示例代码,其中有一个iPhone应用程序和Mac应用程序通过Bonjour进行通信。它确实比你所要求的更多,但它会让你开始。

If by "wifi", you mean "the Internet", you're going to need your own server sitting between the two devices. This is significantly more complex, but still doable, and you'll need to implement the server portion in whatever you're preferred server side technology is.

如果通过“wifi”,你的意思是“互联网”,你将需要你自己的服务器坐在两个设备之间。这要复杂得多,但仍然可行,您需要在服务器端技术的首选项中实现服务器部分。