how to send data from iphone over wifi to application, to print message

吃可爱长大的小学妹 提交于 2019-12-03 03:56:53

问题


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.

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.

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


回答1:


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?

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.

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.

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




回答2:


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.

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.



来源:https://stackoverflow.com/questions/3901659/how-to-send-data-from-iphone-over-wifi-to-application-to-print-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!