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

What I need is to have a simple screen in this Mac app that just prints a string as the iPhone is transmitting strings through the WiFi network.
This string is simply a string value from a slider being adjusted up and down by the user on the iPhone. The data will be sent to the Mac app and then the Mac app will receive this signal from the WiFi network and simply print the values.
This is a constant connection. I'm not trying to sync once. I'm trying to listen to the iPhone device from the Mac to see if the iPhone is sending any more strings as the user slides the UISlider up and down from the iPhone app.
How can I create the client side? Do I need to use Bonjour or something?

In my answer to this question, I provide a link to a sample application that has a Mac component and an iPhone one. These components communicate between one another over a WiFi network, with changes in a label on one being reflected in the other. This is done using Bonjour discovery and the standard networking APIs.
With simple modifications, this could be used to send the continuous updates you need for your particular case.

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-iphone/

Related

Communicating with Windows from an iPhone/iPod

I'm looking to work on an iOS app that would need to send/receive data back and forth between the iPhone/iPod and a service that is running on Windows. Communication-wise, I will be using sockets.
The Phone will send/receive data to/from a Windows service (NOT a web service)
Sockets will be used as a means for communication
The iPhone/iPod will be connected to WiFi using a static IP address
The iPhone/iPod is intended to be as thin client as possible
The intention is to have the Windows Service listen for events from iPhone/iPod. Example:
Input needs to be taken from a UITextField and saved as a string by pressing a button. On the button press, an event must be fired and sent to the Windows Service over WiFi, which will then receive the event, perform a "server-side" action, and send the response back to the iPhone/iPod.
I'm pretty new to iOS development still and I know this is some more advanced stuff, but any help or resources that would help to accomplish this, I'd appreciate it.
Thanks!
This is standard network stuff not related to which platform you're using. On iOS you can do either:
1) use berkley sockets (standard unix stuff).
2) use the Cocoa wrapper for sockets (NSSocketPort etc).
3) use a framework such as MKNetworkKit (here).
I would use option 3 myself :)
One thing in your favour is that Windows machines and iPads are both little-endian, so you don't have to worry about byte-swapping (which you won't anyway if you're just sending strings).
EDIT: For windows to discover your device, you will need either a configuration setup with the IP address details, or to use Apple's bonjour service, or some custom solution.

iOS adhoc wifi sensor data

My iPhone connects over adhoc wifi to a wifi sensor module.
The challenge is to code an app that uses this sensor module. But I'm not sure what specific API's to use to best architect this implementation.
I've started looking into the CocoaAsyncSocket class as it seems to be an appropriate tool for such use.
Does the user always have to manually connect to the adhoc wifi device? (through the Settings app) or can my own app handle the searching, making, and breaking of the wifi connection?
I doubt iOS lets me programmatically toggle whether Wifi is on/off.
Once the sensor data is being received, what container would best handle the stream?
For example, on other platforms, I coded a rotating queue buffer.
Thanks for your input.
Edit: The protocol in question is straight CSV formatted ASCII. Not HTTP, FTP, etc. Just raw data. The app is to simply open a port on the connected IP, and read/write.
Your application cannot turn wifi on/off, or select a wifi network.
Without more information on what protocols this wifi sensor module speaks, it will be impossible for anyone to give more than vague recommendations. If the module can serve data over an http connection, that would probably be ideal. If it requires your software to open a connection on a specific port and communicate over something other than http or ftp, your job will be a bit more complicated. CFNetwork and projects derived from it's usage, such as CocoaAsyncSocket which you mentioned. You can see another implementation of an HTTP connection over CFNetwork in ASIHTTPRequest, that may help as a reference for handling download streams, queuing operations, etc.
As for storing the data, again it's hard to give any concrete recommendations without more information. If you want to store the data to the filesystem of the iOS device, NSData will probably meet your needs. If you need/prefer to use a queue for buffering data, there is a simple category on NSArray which provides queue semantics. The link to CHCircularBuffer in that SO article is dead, but this github project appears to have it.
edit: Here is the official version of the CHDataStructures. I don't know if it's an improvement over the previous link, but it appears to be updated for the more recent iOS SDK.
Add the SSID of your wifi ad hoc networks in settings. When you see the SSID of the network, click the arrow and choose connect automatically. After this, the phone will automatically connect whenever it comes in range. After this, the two devices can communicate using regular socket APIs.

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

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?
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
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.

can iphone use as a receiver?

Can iphone use as a receiver ? Let's say, there will be one app which can connect with a hardware that can send RDF signal. Is that possible iphone to receive signal without any additional hardware ? Thanks.
It's not possible without any additional hardware.
In order to make peripherals work with iPhone you need to contact Apple and become a registered peripheral developer, the membership that allows manufacturers to use the "Made for iPhone" etc labels.
Once you're a member you can get access to the peripherals SDK which allows you to develop for devices that connect to the iPhone using the 30 pin dock connector.
Without developing a device that receives RDF signal that can connect to the iPhone either using the dock connector or a network connection, there's no other way to make the iPhone receive that signal.
If the RDF hardware is able to communicate using standard UDP or TCP/IP based methods then the iPhone can communicate with it using network communication classes. This could be CFNetwork or higher level classes such as NSURLConnection.

iPhone - Browsing iPhone files through computer

I want to be able to send files from an iPhone app to a computer. What would be the easiest way of doing this?
I've made simple server client programs before, but in those, the client has always needed to connect to the server before being able to receive messages from it. There is an app for the iPhone called iSimulate, where you put a server on a Mac (the iPhone simulator), and then you use the iSimulate app of an iTouch or iPhone to send touch events to the server. This app does not require you to type in an ip-address. Instead it presents a list of available computers that have this server up and running.
How exactly is this being done? Can a server broadcast a message over a network, w/o anyone being connected to the server? How does that work? How does a client listen for that broadcast?
Here's a video of the app I'm talking about:
http://www.youtube.com/watch?v=N3Qpd1ycZh4
alt text http://a1.phobos.apple.com/us/r1000/051/Purple/7b/07/70/mzl.mvwjifyc.320x480-75.jpg
That app may be using Bonjour.
I've seen similar apps use a peer-to-peer Bluetooth connection to exchange files between a iPhone and a desktop.