160

I was playing with sockets on local machine with no network connection. See below:

IPAddress address = IPAddress.Any; // doesn't work
IPAddress address = IPAddress.Parse("::1"); // works

So what is exactly ::1 IP address ? Is it the default available IP address or it's the loopback address ? what happens to above code (working line) on a machine with dedicated IP address and network connection ?

EDIT:

exact code is used to bind a specific IP address to socket. Here it is:

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);
}
4
  • 6
    IPAddress.Any is ::0, You should use IPAddress.Loopback for local (loopback) connection.
    – J-16 SDiZ
    Commented Jan 6, 2011 at 3:31
  • I think this should have been posted on SuperUser.com
    – Kamyar
    Commented Jan 6, 2011 at 3:52
  • I'm assuming the part that says IPAddress.Pars is really IPAddress.Parse, correct?
    – Brad
    Commented Jan 6, 2011 at 4:21
  • Reverse question.
    – user202729
    Commented May 12, 2018 at 4:56

3 Answers 3

215

::1 is the loopback address in IPv6. Think of it as the IPv6 version of 127.0.0.1.

See http://en.wikipedia.org/wiki/Localhost

5
  • 1
    at above example IPAddress.Parse("127.0.0.1") doesn't work on my machine.
    – Xaqron
    Commented Jan 6, 2011 at 3:19
  • 1
    @Xaqron - that sounds more like a superuser question, because it probably means something is broken with your IPv4 TCP/IP stack. Commented Jan 6, 2011 at 3:21
  • Xaqron, maybe a firewall is blocking v4 but not v6 traffic? Commented Jan 6, 2011 at 3:25
  • I use Windows Server 2008 Enterprise Edition 64-bit and no third-party firewall installed. I'm wondering why I cannot bind 127.0.0.1 to my socket while ::1 is available.
    – Xaqron
    Commented Jan 6, 2011 at 3:30
  • @Xaqron, can you show us your code that you are trying to use? You say "works" and "doesn't work" but that isn't helpful to us.
    – Brad
    Commented Jan 6, 2011 at 3:37
31

Just to add little more info to it, in IPv6 loopback address is represented as 127 zeroes followed by a 1 i.e (0000... 127 times..1). It's representation should have been like this -> 0000:0000:0000:0000:0000:0000:0000:0001 but we have some short form representation for this. If there are all zeroes in a single block you can replace it by single 0. So it becomes -> 0:0:0:0:0:0:0:0001. Again we can see that we have runs of zeroes, they can be eliminated and we get -> ::0001 -> ::1 .

1
  • 4
    (to be clear, the "127 zeroes" here are in binary, not hexadecimal)
    – user202729
    Commented May 12, 2018 at 4:57
4

The simple answer is that: ::1 is the compressed format of IPV6 loopback address 0:0:0:0:0:0:0:1. It is the equivalent of the IPV4 address 127.0. 0.1

Not the answer you're looking for? Browse other questions tagged or ask your own question.