server-> client multi-threaded version send large files to achieve

Want to quickly transfer a large file, the server and the client as usual single connection to send data packets timeliness is too low, so we need a new way to send a file. We are talking about the server to the client to quickly send large files.

The main idea: to send the specified file server, access to the file size, and the number of threads created to send the file according to the size of the decision. When the detected client connection, it sends the first packet data mainly contains the name of the file (facilitates client backup the same file, taking into account the file type), because the server side to multithreaded transmitted, the client it should be opened as much receiving threads, so the first packet will have to contain a number of threads. Then the server is open thread sends data, the client creates a file, open thread to receive data. And write data to a file.

Specifically: When the server transmits the first packet is completed, turn off the client socket, and then create a connection to the client in the server thread, the server side is directly connected to the detected start sending data. Server packets of data to be included in the total length of this thread is how to send the data start position of the thread is responsible for the piece (cur), each server sends the data length is the number (move_distance) (suggesting that each client receives packet, write files, where should start writing, and where the end of the write). The client receives, directly read data readn server, pwrite in charge from the start position cur thread is responsible to the end of the thread position cur + moved

Realization Summary: written procedures need to be more careful, there is no conceivable method clients to send large files quickly to the server, SA really hurt!

Source: [email protected]: Request2609 / ThreadFile.git

Guess you like

Origin blog.csdn.net/qq_41681241/article/details/90524135