Is it possible to have a Socket that listens and accepts both IPv6 and IPv4 clients? I used a IPv6 socket in C# hoping that it would automatically be backwards compatible but IPv4 clients cause an invalid ip address exception.
Asked
Active
Viewed 1.5k times
2 Answers
7
Have a look here. You can accept IPv4 clients as well as IPv6 clients with the one server socket.

Pixelfish
- 107
- 2
- 10

Matthew Iselin
- 10,400
- 4
- 51
- 62
-
silky: I'd say you're right. I've totally rewritten my answer. – Matthew Iselin Aug 17 '09 at 03:01
-
Looks like one of your links may have evaporated. – Mar 17 '14 at 20:58
7
Set the socket's IPv6Only
option to false
:
Socket MySocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
MySocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
(taken from Matthew Iselin's second link)

Matumba
- 196
- 3
- 10