[Summary] File Transfer and file transfer models in the file transfer model

Source: Internet
Author: User

[Summary] File Transfer and file transfer models in the file transfer model
Preface

The file transfer component has been working for more than a month. This is also a basic concept recently. Here is a simple summary.

Transfer Model

The underlying layer of file transmission uses the open-source c ++ communication component hp-socket (Pullserver, pullClient ). If you are interested, search.

Not much nonsense. Go to the topic

First, all clients must first log on to the server and register on the server. Maintain a ing between the client ID and client information on the server, such as ClientInfo.

// Code snippet ClientInfo {IntPtr connID; string ip; ushort port ;}

Then, the server needs a Dictionary similar to Dictionary <string, ClientInfo>. When client A forwards data to client B, you can find the other party from the ing relationship.

Logon Process

After successfully logging on to the client, you can send the file.

Description

TransferId: Transmission id, which indicates that multiple files are transmitted at the same time.

TransferType: transmission type

TransferCommand: Transmission command

MD5: Check value (md5 or hash, the shorter the better, the faster the algorithm, the better)

FileName: file name.

FileRelativePath: used when transferring folders. The files in the folder must use relative paths. The receiving end saves the files in the folder according to the receiving path and relative path.

Size: the total Size of a file or folder. The total Size is distributed to the application layer to calculate the transmission speed.

CurrendIndex: The index of the current transmission package. It is also the index of the first packet to read the file.

PkgCount: Total number of packages. The acceptor can determine whether the transmission is completed or used for resumable data transfer based on the current index and the total number of packages.

From: sender ID

To: acceptor ID

BodySize: the size of the body transmitted each time.

Custom protocol

Fixed Header + Body

Each packet must follow this Protocol. After the server receives the packet, it must parse the packet and retrieve the Data according to the bodysize in the packet header.

Resumable upload

At the receiving end, each time a packet is received and written to a file, the packet header information is written to a local file (ini or xml file ). Then, when sending the file again, the sender will first send a request packet. Based on the packet header information of the file and the information in the INI file, the receiver will check whether md5 is the same and whether the sender is the same, if they are the same, CurrentIndex + 1 is returned to the sender. The sender can directly read the file package from the location of CurrendIndex + 1 and send it.

Summary

This component has been running for more than a month before, after, and later. The business in this component is complicated and many things need to be considered. Currently, this component is implemented to transmit multiple files and folders at the same time, resumable upload. But there is still a problem with simultaneous transmission of multiple files and folders. When Client A sends A file to client B, client B still sends the file to Client.

Through the design of this component, we have gained a lot and it is also a test of our business capabilities. I have learned more about tcp communication.

This article only shares some ideas. If you are interested, you can search for hp-socket.

Related Article

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.