Componentes.Terceros.RemObj.../internal/6.0.43.801/1/RemObjects Samples/RemObjects SDK for Delphi/Extended File Transfer/ExtendedFileTransfer.Sample.html

67 lines
3.3 KiB
HTML
Raw Normal View History

<html>
<head>
<link rel="stylesheet" type="text/css" href="..\styles.css">
</head>
<body>
<img src="..\..\ro.png" alt="" align="right">
<!-------------------------------------------------------------------------->
<p class="h1"><span>Extended File Transfer Sample</span></p>
<h2>Purpose</h2>
<p>
Some time ago we received several questions in our newsgroup asking how to download
big files using the RemObjects SDK. This sample presents a working solution.
</p>
<h2>How it works</h2>
<p>
The approach is quite simple,instead of downloading a complete file at once, it
is split into small chunks to be downloaded separately. On the client side, these are then combined back into a single file.
</p>
<p>
This &nbsp;sample provides a RemObject server that exposes the content of a folder (see the &nbsp;<b>GetFilesList</b> method in the ExtendedFileTransferService implementation)
and a client that can connect to the server to obtain a list of the files available for downloading. The server also provides another method for downloading a chunk
of a file called <b>DownloadFilePart.</b>
This method requires three parameters:
</p>
<ul>
<li><b>FileName</b> (AnsiString) - name of the file to be downloaded.</li>
<li><b>PartNo</b> (int32) - the chunk part that should be downloaded starting with 1. </li>
<li><b>PartSize</b> (int32) - size of of chunk that should be downloaded. </li>
</ul>
<strong>DownloadFilePart </strong>reads the section of the file with offset <b>PartSize*PartNo</b> and returns the data as a Binary stream to the client.
When we want to download a &nbsp;file we can specify size of chunk (Below the <b>Chunk Size</b> combobox you will see calculated total count of chunks).
Also we can specify the number of
threads we want to use for the downloading operation. Since each partial chunk download
is independent, using threads is quite attractive in this scenario.
<h2>Examine the code</h2>
<ul>
<li>See the implementation of the <b>GetFilesList</b> and <b>DownloadFilePart</b> methods in the <b>ExtendedFileTransferService_Impl</b> class. Look how we can read a chunk of file and return it back to the client.</li>
<li>See <b>DownloadPart</b> function on the client side. This is the method that executes inside each thread we run to download the selected file. Note that we use a separate channel and message for each thread.</li>
<li>Review the <b>bDownload_Click</b> handler. Here we are starting the download. Look how we are using a thread pool for controlling the number of the threads that are
involved in the downloading process.</li>
</ul>
<h2>Getting started</h2>
<ul>
<li>Compile and run the server and client applications.</li>
<li>Put a file into shared folder (you can easily locate and open this folder when you
click on the link label on the server main form).</li>
<li>Get the available files on the client side by clicking the <b>GetFiles</b> button.</li>
<li>Adjust the chunk size and thread count on the client.</li>
<li>Try to download the selected file. At the end of downloading process, you can open
this file to ensure that downloading was successful. </li>
</ul>
<!-------------------------------------------------------------------------->
</body>
</html>