i trying implement data transfer between back-end server , android device request device server information , server responds(udp use because faster , functionality of tcp isn't needed, guess...)
where begin implementing this? have looked @ android docs datagramsocket/packet/socketimplfactory inetaddress , socketaddress.
is right direction? right using http post requests, of code recyclable?
httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2); if (fleetid != null) { namevaluepairs.add(new basicnamevaluepair("fleetid", fleetid)); } namevaluepairs.add(new basicnamevaluepair("user", username)); namevaluepairs.add(new basicnamevaluepair("password", password)); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); //todo: response failure? need ensure success httpentity resentity = response.getentity(); string strentity = entityutils.tostring(resentity); //log.i("response", strentity); return (strentity);
the server , android components can both written in java using the standard java datagramsocket class. quick example can found here (in instance sending string command prompt: http://systembash.com/content/a-simple-java-udp-server-and-udp-client/. basically, make datagramsocket instance given port number , send/recieve data byte[]. however, careful using udp. tcp ensures no data lost when file sent, , therefore ensures data not corrupted sent.
Comments
Post a Comment