Diocp open-source project-diocp3 file transmission demo <resumable upload>

Source: Internet
Author: User

First, the demo was modified on streamcoder. During this period, streamcoderdemo often experienced problems, which caused frequent problems during running and apologized.

The following is the test result. A 3G file (win7.iso) is downloaded from the server ). After transmission, a test is performed using the hash tool, which is the same. Two file textures are attached.

 

 

Below is the hash of the file received by the client

 

Below is the hash of the server Source File

 

Protocols and functions

This demo is used by the client to request files under the server and files. The first request is File Information (file size). After the request is sent to the file, the client requests to download file data, after receiving the data, repeat the request to download the data of the next file until all the data is complete.

The stream File Header of this demo writes the struct information.

Tfilehead = record
Flag: word; // fixed $ A1 mark
CMD: word; // 1, request file data, 2: file data, 10: request file information, 11: File Information Data
Filename: String [255]; // file name
Position: int64; // File Location <specify the location for reading file data when requesting file data>
Size: int64; // data size <the size of the requested data when requesting the file data; when returning the file data (2), it indicates the size of the data.
CRC: Cardinal; // no trial is available.
Performance_result: integer; // 0: Successful; 1: the file cannot be found; 2: An exception occurred; 3: The request parameter is incorrect.

End;

Because the location and size of the downloaded data can be specified in the request, resumable data transfer can be performed. This is a common protocol.

 

Code Description

 

The client performs the main functions by an iocpfiletrans class.

 

To download files \ demofile.jpg from the server, click the modify button.

procedure TfrmMain.btnGetFileClick(Sender: TObject);begin  if not FiocpCoderTcpClient.isActive then  begin    uiLogger.logMessage(‘please do connect‘);    exit;  end;  FFileAsyncTrans.requestFileINfo(edtFileID.Text);end;

 

Requests for file data after a response (onrecvobject)

 

After receiving the data (onrecvobject), after writing the data, continue to request the next piece of data. All data (postion = size) is complete. close the file and complete the download.

 

 

The server has the myclientcontext class to process client requests and return data.

The request file information command returns the file information (file size: lvresult. Size)

 

Request file data, returned Read File size (lvresult. Size), and file data lvfiledata

 

Finally, the file header information and file data are merged into the stream and returned to the client using the writeobject method.

 

The above describes the code in the Process of processing files on the client and server. This demo is just a demonstration, hoping to deepen your understanding of diocp.

 

 

 

Demo path storage samples \ iocp-coder \ streamcoder

Note: the requested file must exist in the files directory of the output path,

The file requested by the client only needs the file name under the files directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.