views:

120

answers:

2

hi, 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?

A: 

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.

Robot K
i mean local network. Thank you for your fast reply. Basically have a slider on my iphone app, when the user updates the slider by moving it up and down i need to send that string with the last value changing from 0 to 99, so if you can image, it will send values as a long string constantly until the has finished adjusting the slider. simple as that. its just a slider setting. but i need to communicate with a mac application so it can receive that string from the wifi local network signal and then print that string in the application. i wil hav a look n c if bounjour helps. anything else?
Pavan
Bonjour was developed to allow apps to communicate over a local network (among other things). It's most likely the approach you want to take and lots of sample code is available, both at developer.apple.com and by searching Google.
Robot K
ok i will definetely take a look. i need to maintain that connection though so the application can keep on listening and listening and my iphone can keep on sending and sending...
Pavan
ok after having a look at the api of bonjour, this is not what im looking for as you cant send data synchronously. I need data to be received straight away on my mac as soon as the user slider from the application is moved up or down. is there anything else
Pavan
A: 

I'll quote myself from a similar question:

http://stackoverflow.com/questions/3902282/create-small-mac-app-that-receives-data-from-iphone-through-wifi-local-network/3902416#3902416

Use 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-ip

Ben