Connect APP to Java program in computer

Hello, I was wondering how could I connect an APP in iOS with Swift to a Java program in my computer, or where could I put this java program so that they can connect to each other so the Java program can run specific functions in the computer when I call the on the iOS app. I have an understanding of Swift and Java I just cannot figure out how to connect a computer Java program to a iOS APP in Swift.


Example: An APP that when I press a button it runs a function in the Java program in my computer.


Thank you, Alvaro.

You might be able to use JNI to use higher-level APIs such as multipeer connectivity from Java, but if it's something simple, you could just listen on a socket and use some application-level protocol you define. iOS app would connect to the specified host / port and send some command; server would interpret that command and do stuff. Not sure how you would do "discovery" of the desktop machine though.

You will probably end up needing to write Swift code for both the phone and the computer, and then have the Swift code on the computer run your Java program somehow.


If you will be using this at a particular location (within a wifi network, etc), the phone and computer can talk using the Multipeer Connectivity Framework.

https://developer.apple.com/library/ios/documentation/MultipeerConnectivity/Reference/MultipeerConnectivityFramework/index.html


If you want to do this remotely, your best bet is probably to have some kind of intermediate data format to store the commands, upload them to iCloud from the phone, and have the computer watch for updates to the data in iCloud and then process them.

https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CloudKitQuickStart/Introduction/Introduction.html

Connect APP to Java program in computer
 
 
Q