使用计算机名称进行套接字连接时出现问题?
我想通过套接字连接将手机连接到电脑。
但只有当我使用IP地址时才成功。我尝试使用计算机名称,但它抛出 UnKnowHostException
。
mySocket = new Socket("192.168.1.100", 10000); //it's ok!
mySocket = new Socket("My_PC_NAME", 10000); //it throw UnKnowHostException !
我的手机正在使用WIFI,其IP是:192.168.1.99
请帮助我, 谢谢 !
I want to connect my cell-phone to PC by using socket connection.
But it's only successful when I use IP Address. I try to use Computer Name but it throws UnKnowHostException
.
mySocket = new Socket("192.168.1.100", 10000); //it's ok!
mySocket = new Socket("My_PC_NAME", 10000); //it throw UnKnowHostException !
My cell phone is using WIFI and its IP is : 192.168.1.99
Please help me,
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是很正常的,因为您的 Android 设备无法访问为 IP 地址分配名称的 DNS。由于它不是您的 PC 网络的一部分,因此您不能使用计算机名称进行套接字连接。
This is quite normal as your android device hasn't access to the DNS that assigns names to IP addresses. Since it isn't part of your PC network, you can't use computer names for the socket connection.