views:

4775

answers:

4

Hi All,

I'm writing an Android App and I'm looking for the fastest (In terms of setup) way for me to send data to a server and receive information back on request.

We're talking basic stuff. I have a log file which tells me how a user is using my application (In beta, I wouldn't runin a user experience by constantly logging usually) and I want to communicate that to my server (That I haven't setup).

I don't need security, I don't need high throughput or concurrent connections (I have 3 phones to play with) but I do need to set it up fast!

I remember back in the day that setting up XAMPP was particularly brainless, then maybe I could use PHP to send the file from the phone to the Server?

The Server would ideally be able to respond to a GET which would allow me to send back some SQL statements which ultimately affect the UI. (It's meant to adapt the presented options depending on those most commonly used).

So there you have it, I used PHP about 4 years ago and will go down that route if it's the best but if there's some kind of new fangled port open closing binary streaming singing and dancing method that has superseeded that option I would love to know.

This tutorial seems useful but I don't really need object serialization, just text files back and forth, compressed naturally.

Android comes with the Apache HTTP Client 4.0 built in as well as java.net.URL and java.net.HttpUrlConnection, I'd rather not add too much bult to my App with third party libraries.

Please remember that I'm setting up the server side as well so I'm looking for an overall minimum lines of code!

Thanks,

Gav

+1  A: 

http://java.sun.com/docs/books/tutorial/networking/sockets/

This is a good background tutorial to Java socket communication.

Hardwareguy
+4  A: 

The easiest solution for you would be to use the apache http client to get and post JSON requests to a php server.

The android already has a JSON builder/parser built-in, as does PHP5, so integration is trivial, and a lot easier than using its XML/Socket counterparts.

If you want examples of how to do this the android side of things, here is a twitter API that basically communicates with twitter via their JSON rest API.

Matt
+2  A: 

private void sendData(ProfileVO pvo) {

  Log.i(getClass().getSimpleName(), "send  task - start");

    HttpParams p=new BasicHttpParams();
    p.setParameter("name", pvo.getName());

  //Instantiate an HttpClient
  HttpClient client = new DefaultHttpClient(p);

  //Instantiate a GET HTTP method
  try {
 HttpResponse response=client.execute(new HttpGet("http://www.itortv.com/android/sendName.php"));
 InputStream is=response.getEntity().getContent();
 //You can convert inputstream to a string with: http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/
} catch (ClientProtocolException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
} catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
}



  Log.i(getClass().getSimpleName(), "send  task - end");

}
A: 

Check out WWW.viewstreet.com developing an Apache plugin specifically for android serverside development for Java programmers

peter