正在向 127.* 发送数据:无法访问主机
我正在尝试发送到在 Windows XP 上运行的 .NET 3.5 应用程序中的环回地址空间。该代码执行简单:
receiver = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 8000);
sock.SendTo(data, len, SocketFlags.None, receiver);
当我运行代码时,我收到无法访问的主机套接字异常。这对我来说似乎很奇怪,因为环回接口始终存在,并且它不应该生成任何无法访问的主机异常。
Windows 7 可以很好地执行代码,这使得问题变得更加奇怪。
所以——如果有人有任何关于在 XP 中运行此功能的提示,我将不胜感激。
编辑:
一些信息:
- 有东西正在监听 127.0.0.2,我的 netstat 显示:
UDP 127.0.0.2:8000 : 5824
我正在运行 XP SP3,并且我的测试计算机上没有防火墙
我在 ping 时注意到 XP 上127.0.0.2,回复返回:
Reply from 127.0.0.1
在 Windows 7 上,回复从我 ping 的地址返回:
Reply from 127.0.0.2
我认为这可能是问题所在,因此它并不是真正的编程问题,更多的是 XP 本身的问题。 ..——
丹
I'm trying to send to the loopback address space in a .NET 3.5 application running on Windows XP. The code does a simple:
receiver = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 8000);
sock.SendTo(data, len, SocketFlags.None, receiver);
When I run the code I get an unreachable host socket exception. That seems strange to me because the loopback interface is always around, and it shouldn't generate any unreachable host exceptions.
Windows 7 executes the code just fine, making the problem that much stranger.
So -- if anyone has any tips on getting this working in XP, I'd appreciate it.
EDIT:
Some info:
- Something is listening on 127.0.0.2, my netstat shows:
UDP 127.0.0.2:8000 : 5824
I am running XP SP3, and there is no firewall on my test machine
I'm noticing on XP when I ping 127.0.0.2, the replies come back:
Reply from 127.0.0.1
On Windows 7 the reply comes back from the address I pinged:
Reply from 127.0.0.2
I'm thinking this could be the issue and as such it's not really a programming problem, it's more of a problem with XP itself...
-- Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它可以与
127.0.0.1
一起使用吗? RFC 说:这似乎表明您不应该依赖
127.0.0.2
工作,除非您专门设置了某些内容。Does it work with
127.0.0.1
? The RFC says:That seems to indicate that you shouldn't rely on
127.0.0.2
working, unless you've specifically set something up.我按照这篇文章的答案中提到的步骤解决了问题:
如何在 Windows 上创建虚拟网络接口?
问题的最初原因是我需要在两个程序之间发送数据:
由于我最初使用 127.* 地址块的计划在 XP 上无法正常工作,所以我选择虚拟网络接口方法。我创建了两个虚拟网络接口:
172.17 地址块已用于其他内容,因此在这里工作正常。这并不完全是我想要的,因为我必须向用户的 PC 添加 2 个环回适配器 - 但它可以完成工作。
- 担
I fixed the problem by following the steps mentioned in the answer to this post:
How do you create a virtual network interface on Windows?
The original cause of the problem was my need to send data between two programs:
Since my original plan of using the 127.* address block didn't work right on XP, I settled for the virtual network interface approach. I created two virtual network interfaces:
The 172.17 address block was already in use for other stuff, so it worked fine here. Not exactly what I wanted because I'll have to add 2 loopback adapters to the user's PC -- but it gets the job done.
--Dan
您是否有一台服务器正在侦听地址 127.0.0.2 处的端口 8000(这与 localhost 不同,尽管是环回)?如果没有,它将无法连接,因为没有任何东西在监听。我怀疑你的Win7盒子上有东西在监听。
应该告诉你什么。
编辑
我怀疑您正在运行 XP SP2:
http://support.microsoft.com/kb/884020(可用修复)
IIRC 他们通过 SP3 消除了此问题
Do you have a server listening on port 8000 at address 127.0.0.2 (which is distinct from localhost, despite being a loopback)? If not, it won't connect because there's nothing listening. I suspect on your Win7 box, there's something listening.
should show you what.
EDIT
I suspect you're running XP SP2:
http://support.microsoft.com/kb/884020 (fix available)
IIRC they removed this problem by SP3
在 Windows 8.0 x64 上,问题似乎仍然存在,有时......
我不知道,问题何时存在,何时不存在,有时甚至会在新启动的 Windows 中出现......
我更改了我的程序以将“localhost”解释为其本地 ip 4 地址。
On Windows 8.0 x64, the Problem seems still exist, sometimes...
i dont know, when the problem exists, and when not, it even appears with fresh booted Windows sometimes...
i changed my programm to interprete "localhost" to its local ip 4 address.