Click here to Skip to main content
12,896,953 members (51,429 online)
Click here to Skip to main content
Add your own
alternative version


89 bookmarked
Posted 29 Jan 2003

IPv6 Client Server Network Applications in C# .NET

, 6 Aug 2003
Rate this:
Please Sign up or sign in to vote.
IPv6 programming in the C# .NET 1.1 environment.

IPv6 Client Server Network Applications in C# .NET

Before reading any further, it is worth mentioning that this requires the .NET framework Version 1.1. This article shows a simple TCP based application in IPv6 as well as how to configure your machine to enable IPv6 .NET development.

Introduction to IP

Many people have heard of IPv6 and its apparent necessity to replace the current IPv4 system of address allocation.

The next two sections give a brief introduction to IPv4 and IPv6, you may want to skip these two sections and go straight to the section IPv6 Client Server Applications in C# .NET 1.1.

A brief introduction to IPv4

IPv4 is the current system in use that assigns IP addresses to a system, every machine connected directly to the Internet has a unique IP(v4) address. An IP address is displayed in human readable decimal form as, where each section can store decimal 255 or Hex FF (8 bits). This means an IPv4 address is 32bits long, allowing 4294967296 (232) unique values. The current population of the world as estimated by the United Nations, stands at approximately 6 billion, with the global population increasing by approximately 79 million a year(PRB01). Although every person in the world does not currently use the Internet, this number is much higher than the amount of addressable IPv4 addresses. In fact, unallocated IPv4 addresses are in short supply, according to the IETF (Internet Engineering Task Force) IPv4 addresses will be exhausted by 2008 (±3 years).

Fortunately methods for getting around the IPv4 problem have been designed. NAT (Network Address Translation) allows N machines on a private network to share one public IP address. In such a setup the private network machine would request data from the Internet; the NAT would translate the user’s local IP address into a public IP address and add information regarding the source of the request. When the reply comes back from the Internet the NAT machine sends this information back to the private machine. This means machines on the private side of the NAT cannot truly communicate bi-directionally with machines on the Internet as the private machines IP address is not valid on the public network. This severely limits what that machine can do, for example, that machine would not be able to fully participate on a distributed network such as GnuTella, as it would not be able to act as the server part of the system. Setting up file transfer on applications such as MSN Messenger also becomes a problem as direct connections between machines cannot be established, especially if both machines trying to communicate are behind NAT gateways.

A brief introduction to IPv6

The problems mentioned in the introduction to IPv4 didn’t go unnoticed within the Internet community. In 1992 the IETF began efforts to find a next generation protocol for the Internet. Two years of proposals later, SIPP (Simple Internet Protocol Plus) was adopted and in 1995 it was named Internet Protocol Version 6 (IPv6). An IPv6 address is displayed in human readable hexadecimal form as xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx, where each divided bit can have a maximum decimal store of 65535 or Hex FFFF (16 bits). This means an IPv6 address is 128bits long, allowing 3.4x1038 (2128) unique values. “If the address space of IPv4 is compared to 1 millimetre, the address space of IPv6 would be 80 times the diameter of the galactic system”(WIDE01). There are many additional features of IPv6, including support for IPSec, a ‘Cluster Address’ field which identifies topological regions and source routing which controls routing in a more precise way (IPv4 currently requires significant routing overhead).

IPv6 Client and Server Applications in C# .NET 1.1

There are a few things you need to setup before being able to write and test IPv6 applications on your machine. Based on your operating system you will need to use different methods to install IPv6. Windows 2000 users should look at, while Windows XP users should read for more information. As the .NET framework will eventually run on all operating systems, other operating system users should go to for more information. The rest of this document will assume you are running Windows XP SP1.

Preparing your system to run IPv6 code

I have installed the Microsoft Loopback device on my machine because I do not have a permanent network connection, however you can use your local system's loopback device for this example (::1, which in IPv4 is equivalent to To install the Microsoft loopback device see

Start a command prompt window and type ipv6 install. After a short period of time your machine will be IPv6 enabled. You can check this by typing ipconfig at the command prompt. You should see an output similar to this:

Windows IP Configuration

Ethernet adapter Microsoft Loopback:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . :
        Subnet Mask . . . . . . . . . . . :
        IP Address. . . . . . . . . . . . : fe80::4cff:fe4f:4f50%4
        Default Gateway . . . . . . . . . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : fe80::54ff:fe55:4e01%6
        Default Gateway . . . . . . . . . :

Tunnel adapter Automatic Tunneling Pseudo-Interface:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : fe80::5efe:
        Default Gateway . . . . . . . . . :

The address fe80::4cff:fe4f:4f50 has been assigned to the Microsoft Loopback device. You should be able to use the ping6 command to ping this address (changing it to the address assigned to your machine).

C:\Documents and Settings\Gary>ping6 fe80::4cff:fe4f:4f50

Pinging fe80::4cff:fe4f:4f50
from fe80::4cff:fe4f:4f50%4 with 32 bytes of data:

Reply from fe80::4cff:fe4f:4f50%4: bytes=32 time<1ms
Reply from fe80::4cff:fe4f:4f50%4: bytes=32 time<1ms

This is the IPv6 address that will be used in the code samples, you can also change this address to your systems loopback device ::1.

Preparing .NET SDK Framework 1.1 for IPv6 applications.

Open the machine.config file that is located in the .NET Framework CONFIG directory (on Windows XP it is located at C:\Windows\Microsoft.NET\Framework\v1.1.XXXX\CONFIG) . Change the XML tag:

<!-- <ipv6 enabled="false"/> --> 
<ipv6 enabled="true"/> 

This allows the framework to parse and resolve IPv6 addresses. We will do a test, in code, to ensue this is working correctly later.

Server Implementation

There are many similarities between building an IPv4 TCP Server and an IPv6 TCP Server. This is great news for developers looking to upgrade current IPv4 applications to IPv6, no matter which language is being used.

First it is necessary to import the following namespaces:

using System.Net.Sockets;
using System.Net;
using System;

Second, check to ensure the system has support for IPv6, this can be done by using the Socket.SupportsIPv6 boolean value.

const int PORT=1979;

if(!Socket.SupportsIPv6) {
    Console.Error.WriteLine("Your system does not support IPv6\r\n" +
        "Check you have IPv6 enabled and have changed machine.config");

We then create an initial listening socket.

Socket listener = new Socket(

The AddressFamily is set as InterNetworkV6 (rather than InterNetwork for IPv4).

listener.Bind(new IPEndPoint(IPAddress.IPv6Any, PORT));

We then bind to the IP Address IPv6Any – this means the application will listen on all NIC addresses on the system. We then call listener.Listen(0) on the socket. This will block until a connection is made to the socket on port 1979. You can check that you are correctly listening to the port by typing netstat –a at a command prompt. You should see a line similar to this in the output:

TCP    yourmachinename:1979   [::]:0          LISTENING       0

We then process anything that comes onto the port and display it to the screen, finishing with a closure of all the sockets and exiting the application –

Socket socket = listener.Accept();

byte[] b = new byte[11];
int len;
while((len = socket.Receive(b)) != 0) {
    System.Console.WriteLine("RX: " +
        System.Text.ASCIIEncoding.ASCII.GetString(b, 0, len));
    b = new byte[11];

The socket accepts 11 bytes of data and then closes all the sockets when the client disconnects.

Client Application

Again, an IPv6 client application is very similar to an IPv4 application.

First import the following namespaces:

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;

System.Threading is included for example purposes to introduce a delay in sending information to the server.

const int PORT = 1979;
const string IPv6_ADDR = "fe80::4cff:fe4f:4f50";

if(!Socket.SupportsIPv6) {
    Console.Error.WriteLine("Your system does not support IPv6\r\n" +
        "Check you have IPv6 enabled and have changed machine.config");

We set the IPv6_ADDR string to the IPv6 address that was returned by ipconfig, change this to the IPv6 address of your machine or ::1 for your systems loopback device.

IPAddress ipa = IPAddress.Parse(IPv6_ADDR);
IPEndPoint ipeh = new IPEndPoint(ipa, PORT);
Socket connection = new Socket(

The Dns.Resolve method does not currently return the IPv6 address specified at IPv6_ADDR. The socket is created with the address family of InternetNetworkV6, exactly the same method as shown in the server code.


byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes("hello world");
for(int x=0; x<10; x++) {
    Console.WriteLine("TX: " + System.Text.ASCIIEncoding.ASCII.GetString(b));


The application then connects to port 1979 at the address IPv6_ADDR and sends the ASCII string ‘hello world’ 10 times every second. The socket is then closed. This terminates both the applications. Remember to run the server application code first before executing the client code.

Further Reading

There is plenty of information on the Internet regarding IPv6. A few very useful links are:

Microsoft’s IPv6 Portal
UK IPv6 Resource Centre
IPv6 News and Links
WIDE Project
IPv6 Information

Also try searching for ‘IPv6’ at


(WIDE01) WIDE Project, Concluded Working Groups, IPv6

(PRB01) World Population Data Set


  • First version 30/01/2003


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gary Brewer
Web Developer
Australia Australia
I am a software developer.

You may also be interested in...


Comments and Discussions

QuestionArticle Viewer Pin
Mohammad Afrashteh9-Feb-11 21:40
memberMohammad Afrashteh9-Feb-11 21:40 
GeneralMy vote of 2 Pin
Soft_banuma4-Feb-10 22:26
memberSoft_banuma4-Feb-10 22:26 
GeneralMy vote of 2 Pin
Soft_banuma4-Feb-10 22:25
memberSoft_banuma4-Feb-10 22:25 
General[Message Deleted] Pin
it.ragester2-Apr-09 21:57
memberit.ragester2-Apr-09 21:57 
Generalnice article Pin
Flow8428-Nov-08 15:03
memberFlow8428-Nov-08 15:03 
GeneralFramework 2.0 [modified] Pin
Aaron Sulwer22-Sep-06 6:54
memberAaron Sulwer22-Sep-06 6:54 
GeneralIPv6 and IPv4 support .... Pin
cdemez6-Mar-06 10:50
membercdemez6-Mar-06 10:50 
AnswerRe: IPv6 and IPv4 support .... Pin
Jim Rogers4-Dec-06 12:41
memberJim Rogers4-Dec-06 12:41 
AnswerRe: IPv6 and IPv4 support .... Pin
Jim Rogers4-Dec-06 12:46
memberJim Rogers4-Dec-06 12:46 
QuestionDoes this really work? Is IPv6 reality? Pin
sytelus28-Feb-05 10:59
membersytelus28-Feb-05 10:59 
AnswerRe: Does this really work? Is IPv6 reality? Pin
Ahmed.mb25-Dec-07 9:53
memberAhmed.mb25-Dec-07 9:53 
AnswerRe: Does this really work? Is IPv6 reality? Pin
Jonathan C Dickinson8-Aug-08 23:05
memberJonathan C Dickinson8-Aug-08 23:05 
GeneralGreat article Pin
Daniël Pelsmaeker19-Aug-04 9:30
memberDaniël Pelsmaeker19-Aug-04 9:30 
GeneralConfigure to run with IPv6 Pin
LorenzoDV16-Sep-03 22:41
memberLorenzoDV16-Sep-03 22:41 
GeneralIPv4 exhausted Pin
Ramon Smits8-Aug-03 0:52
memberRamon Smits8-Aug-03 0:52 
GeneralRe: IPv4 exhausted Pin
Gary Brewer2-Oct-03 0:41
memberGary Brewer2-Oct-03 0:41 
GeneralGood Job - accurate and articulate Pin
Soliant30-Jan-03 10:07
memberSoliant30-Jan-03 10:07 
GeneralRe: Good Job - accurate and articulate Pin
Gary Brewer30-Jan-03 21:33
memberGary Brewer30-Jan-03 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 7 Aug 2003
Article Copyright 2003 by Gary Brewer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid