开发者

Connecting by Hostname

开发者 https://www.devze.com 2023-03-06 12:26 出处:网络
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.

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);
sock开发者_JAVA百科et.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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号