c# - 什么是 IP 地址 '::1' ?

标签 c# ip system.net

我在没有网络连接的本地机器上玩套接字。见下文:

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 版本。

参见 http://en.wikipedia.org/wiki/Localhost

关于c# - 什么是 IP 地址 '::1' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611418/

相关文章:

ubuntu - 没有分配给旧 Ubuntu Box 的 ip

c# - Dns.GetHostEntry Method(String) 实际上做了什么?

.net - System.Net 套接字非常奇怪的自发断开连接

silverlight - 无法将 System.Net.Http 包安装到 Windows Phone 7.1 Silverlight 项目中

c# - 将窗体嵌入到 Windows 窗体中的选项卡控件上

c# - 将 Json 字符串发布到 Web Api Windows Store 8.1

C# 覆盖和访问修饰符关键字首选顺序

c# - 如何在 mvc5 中将文化设置为全局

java - WICKET:如何获取客户端的 ip/地址

python - 是否可以更改|更新我的 "Temporary IPv6 Address"- windows(最好通过 Python)