iPhone App/Java Server Struct Data Issue over WiFi
I currently have an iPhone app that communicat开发者_StackOverflow中文版es 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
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.
精彩评论