To obtain the address of the host that a socket is connected to, you should use getInetAddress()
rather than getLocalAddress()
. Thus, your code could look like this:
public void onClick(View v) {
Socket s = new Socket();
String host ="10.10.20.xxxx";
try {
s.connect( new InetSocketAddress( host, 6000 ), 1000 );
InetAddress inetAddress = s.getInetAddress(); // <---- Here!
String ip = inetAddress.getHostAddress();
Toast.makeText(getBaseContext(), ip , Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}