我在没有网络连接的本地机器上玩套接字。见下文:
IPAddress address = IPAddress.Any; // doesn't work
IPAddress address = IPAddress.Parse("::1"); // works
那么 ::1
IP 地址到底是什么?它是默认的可用 IP 地址还是环回地址?在具有专用 IP 地址和网络连接的机器上,上述代码(工作线)会发生什么情况?
编辑:
确切的代码用于将特定的 IP 地址绑定(bind)到套接字。在这里:
ServicePoint sp = ServicePointManager.FindServicePoint(uri);
sp.BindIPEndPointDelegate = new BindIPEndPoint(Bind);
// here's the bind delegate:
private IPEndPoint Bind(ServicePoint sp, IPEndPoint ep, int retryCount)
{
return new IPEndPoint(IPAddress.Parse("::1"), 0);
}
最佳答案
::1
是 IPv6 中的环回地址。将其视为 127.0.0.1
的 IPv6 版本。
关于c# - 什么是 IP 地址 '::1' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611418/