galbarm
galbarm

Reputation: 2543

Connecting by Hostname

I have a server running on my local machine (Windows 7) that listens to incoming tcp sockets connection. On the same machine I'm running Android Emulator through IntelliJ.

The connection gets established When executing:

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

But when trying by hostname:

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 windows command prompt to ping (by hostname) my computer and other computers over the same network I get replies.
Any idea on how to get it working?

Upvotes: 4

Views: 2984

Answers (2)

Anup Rojekar
Anup Rojekar

Reputation: 1103

Please check DNS entries which resolves hostname & corresponding IP address.

Upvotes: 0

galbarm
galbarm

Reputation: 2543

I got it resolved. Appearently, the emulator, in contrast to some service that runs in windows, does not translate the name comp2 to the full host name which is comp2.letre.ltd. Changing

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

to

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

fixed it

Upvotes: 3

Related Questions