Transfer and store file over established socket connection
===

I established a wifi-direct ad-hoc connection between two android devices and initiated a server-client socket connection. 
The goal is to transfer files likes photos from one device to the other. to implement this, I already managed to send a String from one device to the other (see code below).
How can I now take the next step and send i.e. a photo (I already implemented a view with the gallery, the file should be sent after an on-click action) from one device to the other? 

I'm getting a bit confused with all the input- and outputstreamreaders, bufferedreaders, etc and I don't know how to locally store a received file after transfer.


public static class ServerAsyncTask extends
			AsyncTask<Void, Void, String> {

		private Context context;

		/**
		 * @param context
		 */
		public ServerAsyncTask(Context context) {
			this.context = context;
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				Log.d(DebugTag, "trying to create server socket"); 
				ServerSocket serverSocket = new ServerSocket(8988);
				Log.d(DebugTag, "server socket created"); 
				Socket client = serverSocket.accept();
				Log.d(DebugTag, "server address " + client.getLocalAddress().getHostAddress());
				Log.d(DebugTag, "client connection established " + client.getInetAddress().getHostAddress()); 
				

				String nachricht = null;
				if (mMessage != null) {
					sendMessage(client, mMessage);
					mMessage = null;
				} else {
					nachricht = readMessage(client);
				}

				return null;
			

			} catch (IOException e) {
				Log.e("Exception", e.getMessage());
				return null;
			}
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
		 */
		@Override
		protected void onPostExecute(String result) {
			
			}

		}

public static class ClientAsyncTask extends
			AsyncTask<Void, Void, String> {

		private Context context;
		private String host;

		/**
		 * @param context
		 */
		public ClientAsyncTask(Context context, String host) {
			this.context = context;
			this.host = host;
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				
				Log.d(DebugTag, "trying to create socket");
				Socket socket = new Socket(host, 8988);
				Log.d(DebugTag, "socket opened");
				
				String nachricht = null;
				if (mMessage != null) {
					sendMessage(socket, mMessage);
					mMessage = null;
				} else {
					nachricht = readMessage(socket);
				}
				return nachricht;
			} catch (IOException e) {
				Log.e(DebugTag, e.getMessage());
				return null;
			}
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
		 */
		@Override
		protected void onPostExecute(String result) {

		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.os.AsyncTask#onPreExecute()
		 */
		@Override
		protected void onPreExecute() {
		}

	}
