java - What is localhost for Android? -


What is the 'localhost' address for Android devices?

I am testing a program using the client server on the same app.

Neither works for SERVER_IP = "http: // localhost" and "http://127.0.0.1" InetAddress serverAddr = InetAddress.getByName (SERVER_IP); Socket = new socket (serveradder, serverport);

This returns:

Unable to resolve the host "http: // localhost" : Hostname with Android No address is associated

What is the best way to use a local host?

UPDATE Thanks for all comments: "http: // localhost" / code> is indestructible right "localhost" or "127.0.0.1" or "127.0.0.2" , but I hope the best solution is to answer the answer.

Communicate on TCP, which is a low level protocol compared to HTTP. When you have a socket communication If you are identifying, use the server's bare name (for example, "localhost") or a dotted quad (for example "192.168.0.100").

T includes http: // or any other plan .

If I understand the question correctly and aim to open the socket by the same machine (phone) with the target, then you use

  InetAddress serverAddr = InetAddress.getByName (empty );   

to get the "loopback" interface, which is equivalent to using the local host.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -