Tuesday, September 19, 2006

Does your network application support IPv6?

One of the ways to find out about this is to add an IPv6 address to you computer, and make the application use it. If you observe no crashes and connectivity is fine, then you're okay and there is no need to read further :8-).

What can you do to be IPv6 "compatible"? At first start from here.

If your application is managed one and you use sockets for network I/O then the only thing you should remeber is to check IpAddress.AddressFamily property.

In code this can look like this (error checking is removed for simplicity's sake)

public void Connect(string host, int port)


{

IPHostEntry ipHostEntry = Dns.GetHostEntry(host);

//and now we're creating socket with appropriate address family

IPEndPoint ipEP = new IPEndPoint(ipHostEntry.AddressList[0], port);

Socket socket = new Socket(ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

socket.Connect(ipEP);

}



Many developers are creating sockets assuming that there will always be IPv4. Generally this works as IPv6 addresses are not common these days. But times are changing and we have to be prepared...

No comments:

Post a Comment