title: Send and receive multiple files simultaneously using TcpClient and Tcplistner
body: <p>I'm trying to build a Server\Client program which allows me to transfer multiple files simultaneously between my laptop and home computer.
  My program works just fine when  send a single file; however, when I try to send multiple files simultaneously on separate threads it doesn't work (i don't receive any file on the server)</p>
  
  <p>here's what i did</p>
  
  <pre><code>foreach (string file in FilesCollection)
  {
      Thread Thr = new Thread(ParameterizedThreadStart(Send));
      Thr.Start(file);
  }
  </code></pre>
  
  <p>this is the sending part</p>
  
  <pre><code>    private void Send(string location)
      {
          TcpClient MyClient = null;
          FileStream MyFileStream = null;
          byte[] MyBuffer = null;
          int dSize = 0;
          try
          {
              MyClient = new TcpClient("127.0.0.1", 5555);
              MyFileStream = new FileStream(location, FileMode.Open, FileAccess.Read);
              MyBuffer = new byte[1024];
              Console.WriteLine("Transfering Data...");
              while (true)
              {
                  try
                  {
                      dSize = MyFileStream.Read(MyBuffer, 0, MyBuffer.Length);
                      MyClient.GetStream().Write(MyBuffer, 0, dSize);
                      if (dSize == 0)
                          break;
                  }
                  catch (Exception er)
                  {
                      Console.WriteLine(er.Message);
                  }
              }
              MyFileStream.Close();
              MyClient.Close();
              MyBuffer = null;
              Console.WriteLine("Transfer Complete");
          }
          catch (Exception er)
          {
              Console.WriteLine(er.Message);
          }
     }
  </code></pre>
  
  <p>and this is the receiving part</p>
  
  <pre><code>private void Receive(string location)
  {
      TcpClient MyClient = null;
      FileStream MyFileStream = null;
      byte[] MyBuffer = null;
      int dSize = 0;
      try
      {
          MyClient = MyListener.AcceptTcpClient();
          Console.WriteLine("Connection Made");
          MyFileStream = new FileStream(location, FileMode.Create, FileAccess.Write);
          MyBuffer = new byte[4096];
          while (true)
          {
              dSize = MyClient.GetStream().Read(MyBuffer, 0, MyBuffer.Length);
              MyFileStream.Write(MyBuffer, 0, dSize);
              if (dSize == 0)
                  break;
          }
          MyFileStream.Close();
          MyClient.Close();
          MyBuffer = null;
          Console.WriteLine("Transfer Complete");
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>could someone please tell me what's problem, and also for the client side, do I have to start a tcplistner to receive files from the server?</p>
  
  <p>thank you in advance.</p>