通过主机名连接
我有一个在本地计算机(Windows 7)上运行的服务器,用于侦听传入的 tcp 套接字连接。在同一台机器上,我通过 IntelliJ 运行 Android 模拟器。
连接建立执行时:
Socket socket = new Socket();
InetSocketAddress address = new InetSocketAddress("10.0.2.2", 8082);
socket.connect(address);
但是通过主机名尝试时:
Socket socket = new Socket();
InetSocketAddress address = new InetSocketAddress("comp2", 8082);
socket.connect(address);
我得到:
java.net.UnknownHostException: Host is unresolved: comp2:8082
当我使用 Windows 命令提示符来 ping(通过主机名)我的计算机和同一网络上的其他计算机时,我得到回复。
关于如何让它发挥作用有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了。
显然,与 Windows 中运行的某些服务相比,模拟器不会将名称 comp2 转换为完整的主机名,即 comp2.letre.ltd。
更改
以
修复它
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
to
fixed it
请检查解析主机名和域名的 DNS 条目。对应的IP地址。
Please check DNS entries which resolves hostname & corresponding IP address.