views:

199

answers:

2

How would I send a command to a Mac (which has network sharing turned on) over the Wi-Fi network that both it and the iphone is connected to? In my case I want it to open an application.

A: 

How about using an SSH session?

Richard Inglis
How would I do that?
Joshua
Hey, I just know it's possible, since there's an SSH app available - sorry I can't be more help on the how part :)
Richard Inglis
Ok, Thanks anyway!
Joshua
+4  A: 

By network sharing, I assume you are only sharing files. To launch an app, you'd either need to have Remote Login turned on (which would allow Richard's SSH suggestion) or have an application running on the Mac which is listening on a specific port. Your iPhone app would then communicate over this port. Some iPhone apps have a Mac app counterpart (cf. Reach My Files, Here File, File) for the purpose of communicating with the Mac.

How much work are you expecting the user to do when they install your app? Will you walk them through how to turn on Remote Login option in System Preferences under Sharing (in which case, the iPhone app will need to have the user credentials of a user allowed to login remotely), or have them just install an app? The latter is much more user-friendly, but more work on your part.

To actually launch the app, you can use the open command. Type man open for more details, but basically, to launch, for example, iTunes: open -a iTunes.app.

Don
Its just a basic app to see how it works, just to be used by myself. If I have Remote Login turned on how would I do it? Thanks!
Joshua
If you have Remote Login turned on, you could use an SSH client library like libssh2. See here for a C based example on issuing a command over SSH: http://www.libssh2.org/examples/ssh2_exec.html. Also, check out this answer: http://stackoverflow.com/questions/1624429/how-to-send-command-over-ssh-from-iphone-any-coding-help-or-sample-available.
Don
Really, SSH is for securing the communications channel. You could communicate with your Mac over port 80 for what it's worth. But if you're executing commands remotely, you really want the channel secure.
Don
Thanks for the links, would it be easier to communicate over Port 80? If so how would i do that?
Joshua
Err, I wouldn't. You're talking about executing code remotely over a public port. You probably want as much security around that as possible. To hit a resource over http, you can use NSURLConnection: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html
Don
Okay, I'll go with SSH, do you know of any examples for cocoa? Thanks.
Joshua