tags:

views:

334

answers:

1

I'm trying to create a small HTTP server in C# but I'm having some trouble with IPv6 clients. I have IPv6 support on my machine but when I try to create a listening socket it fails.

Log("Creating server socket on port {0}", LogType.Info, _port);
            _serversocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
            _serversocket.Bind(new IPEndPoint(IPAddress.Any, _port));
            _serversocket.Listen(10);

What am I doing wrong here?

The code throws this exception: The system detected an invalid pointer address in attempting to use a pointer argument in a call

EDIT:

Stack Trace:

at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at TroutServer.Trout.Start(Int32 port) in C:\Users\Chris\Documents\Visual Studio 2008\Projects\TroutServer\trout\trout.cs:line 62

Type is SocketException

+3  A: 

Try:

new IPEndPoint(IPAddress.IPv6Any, _port)
Matthew Iselin
Thank you it finally works!
Chris T