I have an Android app where I am trying to send an image to a server. I did this using Base64 encoding, and it worked pretty well, but it took too much memory (and time) to encode it before sending it.
I am trying to disconnect an Android application to the point where it simply sends an array of bytes and does not work with any encoding scheme, so it will save as many memory and processor cycles as possible.
Here is what I would like for the Android code to look like this:
public String sendPicture(byte[] picture, String address) { try { Socket clientSocket = new Socket(address, 8000); OutputStream out = clientSocket.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); out.write(picture); return in.readLine(); } catch(IOException ioe) { Log.v("test", ioe.getMessage()); } return " "; }
The server is written in Java. How to write server code so that I can correctly get the same byte array? My goal is to save as many CPU cycles on Android as possible.
So far, all the methods I tried have led to corrupted data or thrown exceptions.
Any help would be appreciated.
java android
user489481
source share