SHARE
TWEET

Untitled

a guest Jun 27th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Program
  2.   {
  3.     static void Main(string[] args)
  4.     {
  5.       var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4567);
  6.       var listener = new TcpListener(endPoint);
  7.  
  8.       listener.Start();
  9.  
  10.       AcceptTcpClient(listener);
  11.       while (true)
  12.       {
  13.       }
  14.     }
  15.  
  16.     public static void AcceptTcpClient(TcpListener listener)
  17.     {
  18.       listener.BeginAcceptTcpClient(ClientConnected, listener);
  19.     }
  20.  
  21.     public static void ClientConnected(IAsyncResult asyncResult)
  22.     {
  23.       var listener = (TcpListener)asyncResult.AsyncState;
  24.       var client = listener.EndAcceptTcpClient(asyncResult);
  25.       AcceptTcpClient(listener);
  26.  
  27.       DoAsync(client);
  28.     }
  29.   }
  30.      
  31. class Program1
  32.   {
  33.     private static readonly AutoResetEvent CONNECTION_WAIT_HANDLE = new AutoResetEvent(false);
  34.     static void Main(string[] args)
  35.     {
  36.       var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4567);
  37.       var listener = new TcpListener(endPoint);
  38.  
  39.       listener.Start();
  40.  
  41.       while (true)
  42.       {
  43.         listener.BeginAcceptTcpClient(ClientConnectedHandle, listener);
  44.         CONNECTION_WAIT_HANDLE.WaitOne();
  45.         CONNECTION_WAIT_HANDLE.Reset();
  46.       }
  47.     }
  48.  
  49.     public static void ClientConnectedHandle(IAsyncResult asyncResult)
  50.     {
  51.       var listener = (TcpListener)asyncResult.AsyncState;
  52.       var client = listener.EndAcceptTcpClient(asyncResult);
  53.       CONNECTION_WAIT_HANDLE.Set();
  54.  
  55.       DoAsync(client);
  56.     }
  57.   }
  58.      
  59. class Program2
  60.   {
  61.     static async Task Main(string[] args)
  62.     {
  63.       var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4567);
  64.       var listener = new TcpListener(endPoint);
  65.  
  66.       listener.Start();
  67.  
  68.       while (true)
  69.       {
  70.         var client = await listener.AcceptTcpClientAsync();
  71.         DoAsync(client);
  72.       }
  73.     }
  74.  
  75.     public static void AcceptTcpClient(TcpListener listener)
  76.     {
  77.       listener.BeginAcceptTcpClient(ClientConnected, listener);
  78.     }
  79.  
  80.     public static void ClientConnected(IAsyncResult asyncResult)
  81.     {
  82.       var listener = (TcpListener)asyncResult.AsyncState;
  83.       var client = listener.EndAcceptTcpClient(asyncResult);
  84.       AcceptTcpClient(listener);
  85.  
  86.       DoAsync(client);
  87.     }
  88.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top