How to return a message when calling by a TCP connection? I am working on a communication between Android and Arduino board.

The Android makes a TCP connection with the board and successfully sends some strings to the board. 

The problem is, there is an int in my Arduino code (e.g. int distance) and I would like to pass that back to my Android device.

I have handled the Android side already, but I do not know how to return a message from Arduino.

in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

                //in this while the client listens for the messages sent by the server
                while (mRun) {
                    serverMessage = in.readLine();

                    if (serverMessage != null &amp;&amp; mMessageListener != null) {
                        //call the method messageReceived from MyActivity class
                        mMessageListener.messageReceived(serverMessage);
                    }
                    serverMessage = null;

                }


This is the Android side code but I think that it is not a specific Android problem, there should be some way for Arduino to make a response of an integer variable (without concern what is the source device)?

What I should do in Arduino for making that response?
I'm assuming that you are using an Ethernet shield, as nothing about this is stated. But solution is really similar between many network solution.

Once a TCP connection has been established, it can be used like you would use the Serial;

you'll probably end up having something similar to:

EthernetClient client = server.available(); //accept a new connection
if (client) { //if valid connection
  client.print(distanceValue);
  client.close(); //close connection
}


look at the official API reference for a more detailed list of available command.