title: async TcpClient.Connect() how to use it?
body: <p>Currently I am connecting my client to the server synchronously.<br>
  However, the server is unavailable at times, so I figured using async would be better so I can already gather and format the data I want to send later. I found that the method I am looking for is probably <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.beginconnect%28v=vs.110%29.aspx" rel="nofollow">TcpClient.BeginConnect</a><br>
  Unfortunately I am completely new to async operation, so the parameters weird me out.<br>
  For one: Is there a specific reason I have to use IP and port seperately, i.e. not use an IPEndPoint?<br>
  The more important problem however: AsyncCallback and Object, what are these?<br>
  Do I need to change anything on my server?<br>
  I think I understood that snyc or asnyc is a local choice and doesn't affect the other side, at least not in compatibility.<br>
  Lastly: <a href="http://msdn.microsoft.com/en-us/library/hh191443.aspx" rel="nofollow">Here</a> I read about keywords asnyc and await: Where to use them and how?  </p>
  
  <p>Here's a little pseudo-code to demonstrate what I have and what I want</p>
  
  <pre><code>private static void send(string msg) {
      TcpClient cli = new TcpClient(localEP);
      bool loop = true;
      while(loop) {      //trying over and over till it works
          try {          //is bad practice and inefficient
              cli.Connect(remoteEP);
          } catch (Exception) {
              ;
          }
          if(cli.Connected)
              break;
      }
      var blah = doOtherThings(msg);
      useTheClient(blah);
  }
  </code></pre>
  
  <p>And now how I wished it to work</p>
  
  <pre><code>private static void send(string msg) {
      TcpClient cli = new TcpClient(localEP);
      cli.BeginConnect(remoteEP); //thread doesn't block here anymore + no exceptions
      var blah = doOtherThings(msg); //this now gets done while cli is connecting
      await(cli.connect == done) //point to wait for connection to be established
      useTheClient(blah);
  }
  </code></pre>