Efficiently sending protocol buffer messages with http on an android platform
- by Ben Griffiths
I'm trying to send messages generated by Google Protocol Buffer code via a simple HTTP scheme to a server. What I have currently have implemented is here (forgive the obvious incompletion...):
HttpClient client = new DefaultHttpClient();
String url = "http://192.168.1.69:8888/sdroidmarshal";
HttpPost postRequest = new HttpPost(url);
String proto = offers.build().toString();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("sdroidmsg", proto));
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = client.execute(postRequest, responseHandler);
} catch (Throwable t) {
}
I'm not that experienced with communications over the internet and no more so with HTTP - while I do understand the basics... So my question, before I blindly develop the rest of the application around this, is whether or not this is particularly efficient? I ideally would like to keep messages small and I assume toString() adds some unnecessary formatting.