C # server supporting IPv6 and IPv4 on the same port

Is it possible to have a Socket that listens and receives both IPv6 and IPv4 clients? I used the IPv6 socket in C #, hoping it would be automatically backward compatible, but IPv4 clients throw an invalid IP address exception.

+3
source share
2 answers

Take a look here . You can accept IPv4 clients as well as IPv6 clients with a single server socket .

+5
source

Set the socket parameter IPv6Onlyto false:

Socket MySocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
MySocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);

(taken from the second link by Matthew Iselin)

0
source

Source: https://habr.com/ru/post/1715300/


All Articles