TCP Android client and server code

The server code below which I blogged about during it progress is now working and ready for me to move on to other little projects.

When the server receives a header of “GSIF” (Get Server Image File) it also reads the requested width and height of the image. It will load the image in, scale it to the requested size, compress it as a PNG and then send the data to the client.

EDIT: This would have been much better if I’d have used DataInputStream and DataOutputStream instead of reading bytes.


Whilst the server is running its output is like this:

The TCPServer class code:

The android ASync class to fetch a random image: