Hostname Connection

I have a server running on my local computer (Windows 7) that listens for an incoming tcp socket connection. On the same machine, I run the Android emulator through IntelliJ.

The connection is being established. By doing:

Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress("10.0.2.2", 8082); socket.connect(address); 

But when trying the host name:

 Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress("comp2", 8082); socket.connect(address); 

I get:

 java.net.UnknownHostException: Host is unresolved: comp2:8082 

When I use the Windows command prompt for ping (by host name), my computer and other computers on the same network receive responses.
Any idea on how to make it work?

+4
source share
2 answers

I understood. It seems that the emulator, unlike some service that runs on Windows, does not translate the name comp2 into the fully qualified host name, which is comp2.letre.ltd. The change

 InetSocketAddress address = new InetSocketAddress("comp2", 8082); 

to

 InetSocketAddress address = new InetSocketAddress("comp2.letre.ltd", 8082); 

fixed it

+3
source

Please check the DNS records that resolve the host name and the corresponding IP address.

0
source

All Articles