title: Accept TCP Client Async
body: <p>I've been making a server. I am using TcpListener.AcceptTcpClientAsync() in an <code>async</code> method, but I have no idea how to actually make it work. My code right now is: </p>
  
  <pre><code>private static async void StartServer()
  {
      Console.WriteLine("S: Server started on port {0}", WebVars.ServerPort);
      var listener = new TcpListener(WebVars.LocalIp, WebVars.ServerPort);
      listener.Start();
      var client = await listener.AcceptTcpClientAsync();
  }
  </code></pre>
  
  <p>How do I process the client? Do I just continue coding and it will automagically make new threads of the same method or do I need to do some magic method that will do it for me?</p>
  
  <p>Edit: current code:  </p>
  
  <pre><code>private static Task HandleClientAsync(TcpClient client)
  {
      var stream = client.GetStream();
      // do stuff
  }
  /// &lt;summary&gt;
  /// Method to be used on seperate thread.
  /// &lt;/summary&gt;
  private static async void RunServerAsync()
  {
      while (true)
      {
          Console.WriteLine("S: Server started on port {0}", WebVars.ServerPort);
          var listener = new TcpListener(WebVars.LocalIp, WebVars.ServerPort);
          listener.Start();
          var client = await listener.AcceptTcpClientAsync();
          await HandleClientAsync(client);
      }
  }
  </code></pre>