user7692: 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 && 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?

user643: 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.

7692: <p>I am working on a communication between Android and Arduino board.</p>

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

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

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

<pre><code>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;

                }
</code></pre>

<p>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)?</p>

<p>What I should do in Arduino for making that response?</p>
 643: <p>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.</p>

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

<p>you'll probably end up having something similar to:</p>

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

<p>look at the <a href="http://arduino.cc/en/reference/ethernet" rel="nofollow">official API reference</a> for a more detailed list of available command.</p>
