Android: Sending / Receiving data between two systems
<p>I used TCPsocket for communicating client and server.</p>

<p><strong>Client code:</strong></p>

<pre><code>InetAddress inet = InetAddress.getByName("localhost");
int TCP_SERVER_PORT = 21111;
Socket s = new Socket(inet, TCP_SERVER_PORT);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String outMsg = "connect" + TCP_SERVER_PORT+System.getProperty("line.separator"); 
out.write(outMsg);
out.flush();
Log.i("TcpClient", "Client sent - : " + outMsg);
String inMsg = in.readLine() + System.getProperty("line.separator");
textReceived.append("Client received - : " + inMsg);
Log.i("TcpClient", "Client received  - : " + inMsg);
s.close();
</code></pre>

<p><strong>Server code:</strong></p>

<pre><code>ServerSocket ss = null;
int TCP_SERVER_PORT = 21111;
ss = new ServerSocket(TCP_SERVER_PORT);
Socket s = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String incomingMsg = in.readLine() + System.getProperty("line.separator");
Log.i("TcpServer", "received: " + incomingMsg);
textDisplay.append("Server received - : " + incomingMsg);
String outgoingMsg = "Port " + TCP_SERVER_PORT + System.getProperty("line.separator");
out.write(outgoingMsg);
out.flush();
Log.i("TcpServer", "sent: " + outgoingMsg);
textDisplay.append("Server sent - : " + outgoingMsg);
s.close();
</code></pre>

<p>I used single emulator to test this program in my system. Its working fine. 
Now i need to communicate with two computers.</p>
