title: Indy TCP - Sending and receiving stream
body: <p>Here's how the receiver will receive the stream.</p>
  
  <pre><code> Ms := TMemoryStream.Create;
  
      try
        Ms.Position := 0;
        Connection.IOHandler.LargeStream := True;
        Connection.IOHandler.ReadStream(Ms, -1,false);
      finally
        Ms.Free;
      end; 
  </code></pre>
  
  <p>If the receiver wants to cancel it</p>
  
  <pre><code>procedure TForm1.SpeedButton1Click(Sender: TObject);
  begin
    try Ms.Free; except end; 
  end;
  </code></pre>
  
  <p>This doesn't work well, the application sometimes closes. </p>
  
  <p>Also for the sender...</p>
  
  <pre><code>    Ms := TMemoryStream.Create;
  
      try
        Ms.Position := 0;
        Connection.IOHandler.LargeStream := True;
        Connection.IOHandler.Write(Ms, 0, True);
      finally
        Ms.Free;
      end; 
  </code></pre>
  
  <p>The same with the sender in canceling the stream.</p>
  
  <pre><code>procedure TForm1.SpeedButton1Click(Sender: TObject);
  begin
    try Ms.Free; except end; 
  end;
  </code></pre>
  
  <p>What is the proper way to cancel the stream that is being send or receive ?</p>