Advertisement
AyrA

IPv4 & IPv6 single socket listener

Mar 29th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3.     //This code makes a single socket listen for IPv4 and IPv6 connections
  4.     Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
  5.     sock.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);
  6.     sock.Bind(new IPEndPoint(IPAddress.IPv6Any, 8000));
  7.     sock.Listen(4);
  8.     Socket client = sock.Accept();
  9.     Console.WriteLine("Client has connected successfully with the server");
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement