How to create a Mac/PC server app that interacts with iPhone/iPad App? - iphone

Can someone please point me in the right direction to create a Mac/PC server app that runs in the background and connects to an iPad app over the local WiFi network?
No matter how I phrase a search on Google it just brings up various apps like Remote Mouse and whatnot and no tutorials or even a hint of where to start.
I just need to send simple commands from iPad to computer over local wifi. A point in the right direction and I can likely fill in the blanks.
Thank you.
Thomas
EDIT: I am using web languages for the iPad version that I will build as a native app using open source tools.

OK, then. It actually depends on what you really need. I made the assumption you need real-time and perhaps binary data transfer.
Your best bet is to write your server application using standard C or C++ so it compiles on both as simply as possible.
If you want to avoid all the burden of writing a protocol for service discovery or asking users to enter the ip address of your server you will use a mDNS implementation for your server and your iPhone app.
If I were you I would try bonjour: http://www.apple.com/support/bonjour/
on iPhone You could start here: http://developer.apple.com/library/mac/#documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/PublishingServices.html
Once you have your sockets you will have to implement a networking protocol between your server application and your iPhone app.
You will have to be careful about byte ordering and little subtle problems with latency, disconnections and other problems inherent to networking and WiFi.
In windows you will want to register your application as a service and in Mac OS X/UNIX you'll probably want to deamonize it.
Good luck!

Related

How to do peer-to-peer communication in an iPhone app?

I'm trying to write a simple chat application for the iPhone (as an experiment). Is there a simple way for two devices to discover each others' IP addresses, and given the addresses is there a simple API or protocol that would let me send text messages back and forth?
I've investigated SIP (specifically Sofia and eXosip), but these tools exist as C libraries and are beyond my current ability to port them to the iPhone.
Update: I'm trying to connect two devices over the Internet (i.e. not over Bluetooth or a local wireless network, which is what GameKit does).
You're going to need a server that provides the match making service. Game Center makes this pretty easy, but your users will have to have Game Center accounts.
Alternatively, you can set up an XMPP (formerly Jabber, it's what powers Google Chat) server (I've never done this, but there are several available) and use the XMPP Framework for Cocoa. There are instructions for using it in iPhone apps here.
I'm sure there are other chat servers and client source also available. IRC and Mobile Colloquy come to mind.
Finally, you could write your own server using your favorite server language / framework. This isn't too hard (I've done it myself), but it's far from what I'd call simple, and I wouldn't use it for a production system.
There is support for exactly this kind of ad-hoc peer-to-peer networking in GameKit. Have a look at the second half of the GameKit documentation for details:
http://developer.apple.com/library/ios/#documentation/...
NSNetService is a good option.
Take a look at WebRTC Datachannels. WebRTC is a newer option with native iOS support a standard that is still being finalized, but it is more flexible should the iOS app need to communicate with browser or even android peers

Sending data between OSX and iPhones/iPads

I am wondering how I can send data between a machine and a mobile device. I know about the game kit an have read a bit about bonjour (but don't know to much about it), but would like to know some expert thoughts on what the best way is.
What I basically want to build is a one way traffic application that sends data from OSX to the mobile device (iPhone, iPod touch or iPad). The data send is either pictures, text (of a certain size and position ect) or video. The mobile device just has to receive this data and display it... nothing more.
My guess is that a WiFi solution would be best.
How could I best do this? Are there any tutorials that might help me putting this together?
Thanks in advance!
Best regards,
Paul Peelen
As no reply yet . . .
Bonjour is more focused on LAN networks, so would restrict you to WiFi.
It's also more of a service discovery standard - your Mac app would advertise the service on the LAN, and clients could see it - but your actual app communications will run on a different TCP socket, using whatever protocol is appropriate.
This linked answer may be helpful (although you will want CFNetwork in reverse - pushing from Mac to phone)
[iPhone]: How send output stream via wireless network?
For video you are probably better off looking for higher level frameworks (i.e. the AV ones).
Without knowing the full details of what you want to do, I wonder if rather than pushing data to the iPhone, the best thing would be to send a lightweight notification to the iPhone (AMQP, XMPP, or similar protocol) passing a URL back to the resource on the Mac - that way you could use standard HTTP GET for images, video, etc, on the iPhone side, throw the URL at a webkit view to display - and on your Mac side you could then use an off-the-shelf web server (Apache, or an embedded HTTP server within your code).

What is the best way to implement a Server-Client connection between an iPad and multiple iPhones?

Based on a college-project I'm trying to realize a relatively simple game (Poker) where an iPad acts as Server and multiple iPod-Touchs connect to it as Clients.
Gamekit seems to drop out, since those old ipod-touch-devices don't have bluetooth-support.
Are there already some Frameworks out there simplifying the process, or do I have to fall back on TCP-Streaming-Sockets and implement it myself?
For your task I suggest you have a look at ThoMoNetworking or AsyncSocket.
ThoMoNet is a very simple setup that is specifically developed for fast and easy prototyping and easy to set up. Is will automatically create a bi-partite graph between all instances of you application it finds in the local network. So If you keep your iPad as the server and the iPhones as clients this will come down to less than 10 lines of code to set up.
AsyncSocket is a commonly used framework with ports to PC as well but requires more code to write. On the other hand it will allow you to do more fancy things, should you need them.
Distributed objects are not yet available on iPhone OS, so excluding GameKit you may try using Bonjour networking. Otherwise, you may try using web services with some of the available libraries. If Bonjour and web services are not a choice/possibility, then you have to revert to old plain sockets.

iPhone interaction between PC app and iPhone app using USB

I know since the 3.0 SDK we can use accessories, so my question is simple, what is the process to make an iPhone app and PC (or Mac) app interact, using the USB ?
I don't ask you any code, but just the paths and the keys for making that work.
Have I to access the iPhone disk through SSH and work with files ?
Or can I send data from the iPhone app and intercept (get) it on the PC app (and send data from PC to iPhone) ?
Thanks, and if this question is stupid, just tell me, I didn't find on Dev Center (I don't really know what I have to looking for...) !
Edit : I read some news from Microids, they will synchronize PC and iPhone games (i.g here), and somewhere (I can't find it again) they say connecting the iPhone on the USB, so I think this is possible
USB access on the phone is only supported via the External Accessory Framework. You cannot hook the iPhone up to arbitrary USB devices, the devices actually have to support the EA protocol. You can get more details about it via the Made for iPhone program.
Other than that there is no USB access available on to applications.
You want the External Accessory Framework. Having said that, I'm not sure that Apple's intention was for you to communicate with an application on a PC/Mac. It's really for talking to accessories such as iPod docks, remote controls, etc. Apple may not allow an application that talks to a PC in this manner in the App Store.
You might be interested in ssh_relay (earlier called iphone_tunnel).
There is a /System/Library/Lockdown/Services.plist on your iPhone and you can start any such services via AMDeviceStartService and then communicate with it.
The ssh_relay demonstrates how to do that by having a simple port forwarder as a service on the iPhone site and the client application on your PC, so you can forward any local iPhone port to your PC. This is not exactly what you wants here (it is handy in the case you have already another service running on the iPhone which communicates via simple TCP and you want to access that; for example SSH) but based on this example, it should be straight-forward to have any communication between the service (in Services.plist) and your PC.

How do I write a desktop application that syncs with the iPhone?

For example, how would I write a program like senuti? Are there any libraries I can use for this? It would be ideal if I could do this in Python or .Net, but I'm open to other things as well.
There are three things you can do:
Add some code to your iPhone application which acts as some kind of server (http, SMB, etc). Then your mac/windows full client application can connect to this server over wifi. This is safe and reliable, but unfortunately the app will have to be running on the iPhone at the time of sync.
Sync to the "cloud". EG: Have your iPhone app save some data to a web server on the internet (you could use amazon EC2, windows Azure, or even just a PHP script running on a cheap hosting account), and then have your windows/mac client also connect to this web server to retrieve the data. This is the most user-friendly, but it requires you to pay for the hosting of the web server, and will be unsuitable for large amounts of data
Violate the EULA and try to reverse engineer the way iTunes communicates with the iPhone.
This is how senuti works, but I wouldn't recommend it, as they're constantly having to play catchup with apple changing the format underneath them, and they are probably exposed to some kind of legal action, if apple ever bothered to sue them.
i believe Version 3.0 will resolve this as it allows you to program apps to the USB interface. check out some of the documentation for that in the External Accessory framework.
it would still require the app to be open, so essentially would mean two syncs (or more if you have multiple apps)
There is no legal / official way of doing this. Creating a program that would sync with an iPhone would violate the EULA you agree to when using the iPhone and iTunes.
Not only is it illegal, but it's also impossible to do this reliably. Apple could break the method at any time without any notice, and it would pretty much be a cat-and-mouse game.
I only know of one application that something of the kind, and it is the iToner application which synchronizes ringtones.