AyrA icon

IPv4 & IPv6 single socket listener

AyrA | PRO | 03/29/16 09:28:51 PM UTC | 0 ⭐ | 453 👁️ | Never ⏰ | []
C# |

450 B

|

None

|

0 👍

/

0 👎

static void Main(string[] args)
{
    //This code makes a single socket listen for IPv4 and IPv6 connections
    Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
    sock.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);
    sock.Bind(new IPEndPoint(IPAddress.IPv6Any, 8000));
    sock.Listen(4);
    Socket client = sock.Accept();
    Console.WriteLine("Client has connected successfully with the server");
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎