views:

137

answers:

1

I currently have an iPhone app that communicates with a C++ server running on a computer, over WiFi. This app is sending its data (x,y coordinates) in a c-struct to the server. For further development, we would like the iPhone application to communicate directly with a java server, however the major issue is that java does not have the ability to emulate or use a c-struct. What would be the best way to send data (x,y coordinates) between the two devices? I can already establish a connection between the two devices. More specifically how I would receive the data and process it on the Java end.

Thanks for your help,

Alex

+1  A: 

You might set up a RESTful web service on the Java back-end.

On the iPhone, package ("serialize") the data into an HTTP POST request however you want (e.g. JSON, XML, etc.) and send the request to the web service.

For example, a JSON object might look something like:

{ "coordinates": [ { "x" : "100", "y" : "200" } , { "x" : "20", "y" : "40" } ] }

The web service responds to the POST request by unserializing this JSON data into a Java-specific data container, such as an ArrayList<Point> collection.

ASIHTTPRequest makes the iPhone side of this setup pretty easy, with its ASIFormDataRequest class.

Java has JAX-WS that facilitates setting up RESTful services.

There are numerous JSON encoding and decoding frameworks and libraries for Objective-C and Java in the aforementioned link.

Alex Reynolds
How do you suspect performance would be for the two devices communicating? The iPhone device is essentially acting as a trackpad for the computer and has the potential to send coordinates several times a second.
adimitri
In that case, you might look at a UDP implementation on the client and server ends: e.g. http://code.google.com/p/cocoaasyncsocket/ and http://www.devx.com/getHelpOn/10MinuteSolution/20426
Alex Reynolds