What is 'localhost' address for Android device?
I'm testing a program using client and server at the same app.
neither SERVER_IP ="http://localhost"
nor "http://127.0.0.1"
works for
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
socket = new Socket(serverAddr, SERVERPORT);
it gives:
Unable to resolve host
"http://localhost"
: No address associated with hostname android
What is the best way to use localhost?
UPDATE
Thanks to all comments: "http://localhost"
is incorrecct. Right is "localhost"
or "127.0.0.1"
or "127.0.0.2"
, etc. But I hope the best solution is the marked answer.