CN108600377A - A kind of pause method of file download, device, terminal and storage medium - Google Patents
A kind of pause method of file download, device, terminal and storage medium Download PDFInfo
- Publication number
- CN108600377A CN108600377A CN201810396744.8A CN201810396744A CN108600377A CN 108600377 A CN108600377 A CN 108600377A CN 201810396744 A CN201810396744 A CN 201810396744A CN 108600377 A CN108600377 A CN 108600377A
- Authority
- CN
- China
- Prior art keywords
- target
- downloaded
- file
- download
- pause
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/06—Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The embodiment of the invention discloses a kind of pause method of file download, device, terminal and storage mediums.This method includes:Obtain the corresponding target network address of file to be downloaded;Destination request message is generated according to default requesting method and target network address, and destination request message is sent to destination server;When target response code in the target response message for receiving destination server transmission is success response code, file to be downloaded is downloaded according to target response message;If detecting, download state variable is that pause identifies, and stops calling the poll methods in asynchronous read-write service object.The function that HTTP files are downloaded in pause may be implemented in the technical solution of the embodiment of the present invention, and the user experience is improved.
Description
Technical field
The present embodiments relate to network technology more particularly to a kind of pause method of file download, device, terminal and deposit
Storage media.
Background technology
With the development of network technology, user often downloads required file in the client.Currently, being based on HTTP
File in (HyperText Transfer Protocol, hypertext transfer protocol) procotol download server is a kind of
Most commonly seen method for down loading.
In general, user is when downloading larger file, it may be necessary to suspend the file downloaded.However, existing
There is the HTTP method for down loading in technology not to be provided with pause and restore the function of downloading, affects user experience.
Invention content
An embodiment of the present invention provides a kind of pause method of file download, device, terminal and storage mediums, temporary to realize
It stops and carries the function of HTTP files, promote user experience.
In a first aspect, an embodiment of the present invention provides a kind of pause methods of file download, including:
Obtain the corresponding target network address of file to be downloaded;
Destination request message is generated according to default requesting method and the target network address, and to described in destination server transmission
Destination request message;
When it is success response code to receive the target response code in the target response message that the destination server is sent,
The file to be downloaded is downloaded according to the target response message;
If detecting, download state variable is that pause identifies, and stops calling the side poll in asynchronous read-write service object
Method.
Second aspect, the embodiment of the present invention additionally provide a kind of pause device of file download, including:
Target website acquisition module, for obtaining the corresponding target network address of file to be downloaded;
Destination request message generation module, for generating destination request report according to default requesting method and the target network address
Text, and send the destination request message to destination server;
File to be downloaded download module, for receiving the target in the target response message that the destination server is sent
When answer code is success response code, the file to be downloaded is downloaded according to the target response message;
Pause module is downloaded, if for detecting that download state variable is that pause identifies, stops calling asynchronous read-write
Poll methods in service object.
The third aspect, the embodiment of the present invention additionally provide a kind of terminal, and the terminal includes:
One or more processors;
Memory, for storing one or more programs;
When one or more of programs are executed by one or more of processors so that one or more of processing
Device realizes the pause method of the file download as described in any embodiment of the present invention.
Fourth aspect, the embodiment of the present invention additionally provide a kind of computer readable storage medium, are stored thereon with computer
Program realizes the pause method of the file download as described in any embodiment of the present invention when the program is executed by processor.
The embodiment of the present invention according to the target network address for presetting requesting method and file to be downloaded by generating destination request report
Text, and send destination request message to destination server;Mesh in the target response message for receiving destination server transmission
When mark answer code is success response code, file to be downloaded is downloaded according to target response message;And works as and detect download state variable
When identifying for pause, stop calling the poll methods in asynchronous read-write service object, to stop receiving the number of file to be downloaded
It is believed that breath, pause function when HTTP files is downloaded to realize, and can stop the file downloading at any time, meet
The individual demand of user, the user experience is improved.
Description of the drawings
Fig. 1 is a kind of flow chart of the pause method for file download that the embodiment of the present invention one provides;
Fig. 2 is a kind of flow chart of the pause method of file download provided by Embodiment 2 of the present invention;
Fig. 3 is a kind of structural schematic diagram of the pause device for file download that the embodiment of the present invention three provides;
Fig. 4 is a kind of structural schematic diagram for terminal that the embodiment of the present invention four provides.
Specific implementation mode
The present invention is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched
The specific embodiment stated is used only for explaining the present invention rather than limitation of the invention.It also should be noted that in order to just
Only the parts related to the present invention are shown in description, attached drawing rather than entire infrastructure.
Embodiment one
Fig. 1 is a kind of flow chart of the pause method for file download that the embodiment of the present invention one provides, and the present embodiment can fit
The case where for suspending the HTTP files in download server.This method can be executed by the pause device of file download, should
Device can be realized by the mode of software and/or hardware, be integrated in client.This method specifically includes following steps:
S110, the corresponding target network address of file to be downloaded is obtained.
Wherein, file to be downloaded refers to the HTTP files for needing to download from server using http protocol.Each wait for down
Part of publishing papers corresponds to a target network address.Target network address in the present embodiment refers to the URL (Uniform based on http protocol
Resoure Locator, uniform resource locator) address.The corresponding target network address of file to be downloaded can be inputted by user
The mode of network address obtains, and the corresponding website links of file to be downloaded can also be clicked directly on by user to obtain.Illustratively,
The entitled version.ini of file to be downloaded, the corresponding target network address of this document are http://www.douyu.com/
Pcclient/version.ini, wherein www indicates that the agreement of this document version.ini is http protocol,
Www.douyu.com indicates that host address, i.e. domain name addresses, pcclient/version.ini indicate file to be downloaded
The resource path of version.ini can be seen that file to be downloaded version.ini is stored according to the target network address
Under the pcclient catalogues of this host of www.douyu.com.
S120, destination request message is generated according to default requesting method and target network address, and mesh is sent to destination server
Mark request message.
Wherein, requesting method include but not limited to GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE and
CONNECT.Default requesting method can be pre-set according to actual conditions and demand.Illustratively, HTTP texts usually are being downloaded
GET request method is used when part.Destination request message can be directed to the HTTP message that file is downloaded in destination server request.This
Destination server in embodiment refers to the corresponding HTTP server of target network address, for receiving and answer file download apparatus hair
The destination request message sent.
Optionally, S120 includes:
According to the target domain name addresses in target network address, target ip address and target port are determined;Based on target ip address
And target port, utilize asynchronous socket and asynchronous read-write service object's linking objective server;In linking objective service
When device success, destination request message is generated according to default requesting method and target network address, and send target to destination server and ask
Seek message.
Wherein, http protocol is assisted based on TCP (Transmission Control Protocol, transmission control protocol)
The upper layer application protocol of view.Generally conventional Transmission Control Protocol is needed according to IP address and port come Connection Service device, therefore is being initiated
When TCP connection, it is necessary to target ip address and target port are provided, illustratively, IP address 127.0.0.1.It is assisted based on HTTP
The only domain name addresses that the target network address of view provides, to need to parse to the target domain name addresses in target network address, really
Fixed target ip address corresponding with target domain name addresses and target port.Optionally, by calling gethostbyname to obtain
Hostent structures, and according to the h_addr_list fields in hostent structures, parse target ip address.Specifically, passing through
Gethostbyname network APs I (Application Programming Interface, application programming interface) is by mesh
Mark domain name addresses is transferred to as parameter in gethostbyname functions, to obtain a hostent structured data, and root
According to the h_addr_list fields in the hostent structures, inet_ntoa is called to obtain h_addr_list [0], thus by h_
The corresponding IP address of addr_list [0] is determined as the corresponding target ip address of target domain name addresses.HTTP service in the present embodiment
The port of device acquiescence is 80, so as to directly determine that target port is 80.Illustratively, file to be downloaded version.ini
Target network address be http://www.douyu.com/pcclient/version.ini, by by domain name addresses
Www.douyu.com is transmitted to as parameter in gethostbyname functions, so that it is determined that corresponding with www.douyu.com
Target ip address.According to determining target ip address and target port, TCP SOCKET sockets and I/O read-write services pair are utilized
As sending TCP connection, to linking objective server.
Optionally, it is based on target ip address and target port, utilizes asynchronous socket and asynchronous read-write service object
Linking objective server, including:
Create asynchronous read-write service object;Asynchronous socket is created, and read-write service object is passed to socket
Constructed fuction in;The contiguous function of socket is called, and target ip address and target port are passed in contiguous function;According to
Parameter information in connection call back function determine destination server whether successful connection, wherein connection call back function is for receiving
The connection result of contiguous function.
Wherein, the present embodiment is in linking objective server, and boost is used to increase income the library ASIO (asynchronous IO) in library.
Optionally, by new operators, it is boost to create a type::asio::The asynchronous read-write service pair of io_service
As can read-write service object be labeled as m_ioService.By new operators, it is boost to create a type::
asio::ip::tcp::The asynchronous socket of socket, and the m_ioService of establishment read-write service objects are passed to this
In the constructed fuction of type, read-write service object can take as first parameter of the constructed fuction, and by incoming read-write
The socket of business object, which can mark, is.By calling the contiguous function in the socket m_socket created, such as
Target ip address and target port are passed into the contiguous function by async_connect functions, with linking objective server.
The contiguous function of socket is for realizing the asynchronous connection to destination server in the present embodiment, it is also necessary to provide a connection
Call back function OnConnectResult is received with judging whether the execution of the contiguous function succeeds using connection call back function
The connection result of the contiguous function.Optionally, it when entering connection call back function, is connected in call back function by judgement
Error parameter informations whether equal to 0 come determine destination server whether successful connection.If error parameter informations are equal to 0, table
Show linking objective server success, if error parameter informations be not equal to 0, then it represents that linking objective serv-fail, need again into
The connection of row destination server.
Optionally, after the success of linking objective server, it is also necessary to initiate a network and read request of data, to prepare to connect
It receives to connect the response data of destination server.Receiver function namely in calling socket, such as async_read_some
When function, an asynchronous exclusive rights request is delivered in read-write service object.And when calling receiver function, it is also desirable to carry
For a reception call back function OnRecvMessage, to receive the network data of destination server transmission.It is socketed in the present embodiment
Receiver function async_read_some in word be for realizing the network data that destination server is sent Asynchronous Reception and
It downloads.
Optionally, it is GET methods to preset requesting method;Correspondingly, generating mesh according to default requesting method and target network address
Request message is marked, and destination request message is sent to destination server, including:
According to target network address, the heads GET and host head are constructed;According to the heads GET and host head, destination request is determined
Header;According to the transmission function in socket, destination request header is sent to destination server.
Wherein, after the success of linking objective server, destination request message can be sent to destination server.When default
When request method is GET methods, the HTTP request header data of text type are typically sent to destination server.This
It needs to use " r n " line feed in request message head in embodiment, and there are one without any at the end of text data
" r n " newline of data.When constructing the heads GET, it is necessary to be started with GET character strings, add the master in target network address later
The version number of machine title and http protocol.When constructing the head host (Host), started with Host character strings, adds target later
Host address in network address.Illustratively, if target network address is http://www.douyu.com/pcclient/
Version.ini, then the heads GET constructed be GET pcclient/version.ini HTTP/1.1 r n, the host of construction
Head is Host:www.douyu.com\r\n.After the heads GET constructed, the host header constructed is and then added
Portion, so that it is determined that the text-string of destination request header.By calling the transmission function in socket, such as async_
The text-string of destination request header is sent to destination server by write_some functions.It is socketed in the present embodiment
Transmission function async_write_some in word is for realizing the asynchronous transmission to request data.
Optionally, after S120, further include:
The receiver function in socket is called, and the target response that destination server is sent is received using call back function is received
Message.
Wherein, after destination request message being sent to destination server, if destination server responds successfully, target clothes
Business device sends target response message corresponding with destination request message to file downloading device.The present embodiment can be covered by calling
The receiver function async_read_some in word is met, when destination server responds successfully, just enters reception call back function
OnRecvMessage come receive destination server transmission target response message.
It should be noted that calling contiguous function async_connect, the receiver function of socket in the present embodiment
Async_read_some and transmission function async_write_some is asynchronous, so needing to call read-write service object
Poll methods all asynchronous events of socket are handled.
S130, the target response code in the target response message for receiving destination server transmission are success response code
When, file to be downloaded is downloaded according to target response message.
Wherein, the target response message in the present embodiment refers to that destination server is generated and sent according to destination request message
Http response message.Target response code can be the request results for describing to send the when of asking to destination server and return,
It may determine that destination server is successfully to have handled request according to target response code, mistake still occur.When receiving mesh
When marking response message, further include:Target response message is parsed, determines the target response code in destination request message.
In target response message, started with HTTP version numbers, after HTTP version numbers followed by be exactly target response code.Illustratively,
If being in target response message " HTTP/1.1 200 ", it is determined that target response code is 200, if being in target response message
" HTTP/1.1302 ", it is determined that target response code is 302.Success response code in the present embodiment can be 200.When target is rung
Answer code be success response code when, indicate destination server be successfully processed request, at this time can be directly according to target response message
To download file to be downloaded.
Optionally, file to be downloaded is downloaded according to target response message in S130, including:
In the predetermined position of disk, a target text identical with the file to be downloaded title in target network address is created
Part;The target sizes information of file to be downloaded is determined according to the length field information in the head of target response message;Call set
The poll methods in the receiver function and read-write service object of word are connect, the data of file to be downloaded are downloaded according to target sizes information
Information;Data information after download is written into file destination.
Wherein, the predeterminated position of disk refers to the download location of file to be downloaded, and predeterminated position can be user according to reality
Storage location in the disk that border demand is chosen in advance.Target network address is parsed to obtain the file name of file to be downloaded,
Such as version.ini.It is identical with this document title in the predetermined position establishment one of disk by calling fopen functions
File destination, such as version.ini files.Since the target response code in target response message is success response code, then obtain
Target response message head in certainly exist length field information, such as Content-Length fields, basis at this time
Content-Length fields determine the target sizes information of file to be downloaded.Illustratively, if the Content- obtained
Length fields are " Content-Length:1000 ", then show that the target sizes of file to be downloaded are 1000 bytes.This implementation
Target sizes information in example can determine before creating file destination, can also be determined after creating file destination, this
Embodiment is not specifically limited the sequencing of the determination step of target sizes information and the foundation step of file destination.It calls
Poll methods in the receiver function async_read_some and read-write service object of socket, and target sizes information is passed
Enter in receiver function async_read_some, so as to be downloaded to receive using call back function OnRecvMessage is received
The data information of file.After the completion of downloading the data information of file to be downloaded on destination server, by calling fwrite
The data information of file to be downloaded is written in the file destination of establishment by function, to store file to be downloaded.
Optionally, the poll methods in the receiver function and read-write service object of socket are called, are believed according to target sizes
Breath downloads the data information of file to be downloaded, including:
The poll methods in the receiver function and read-write service object of socket are called, according to connecing in reception call back function
Receive amount of bytes and the downloaded byte amount of having downloaded in variable determine current byte with;If current byte and be not equal to target sizes
Information, then by the downloaded byte amount downloaded in variable be updated to current byte and, and call receiver function and poll again
Method;If current byte and be equal to target sizes information, complete the download of the data information of file to be downloaded.
Wherein, need to call the side poll in the receiver function and read-write service object of socket in the present embodiment simultaneously
Method so that receive call back function and receive the file data that destination server is sent, if only calling the receiver function of socket, and not
The poll methods in read-write service object are called, then file data can not be received by receiving call back function.The present embodiment exists
When the poll methods called receiver function async_read_some and read and write in service object receive data, each maximum reading
It is 8192 bytes to take size, when the content size of file to be downloaded is more than 8192 byte, needs repeatedly to call async_read_
Some functions and poll methods, to complete the download to entire file content.In receiving call back function OnRecvMessage,
First data parameter indicates that the file data content received, second size parameter indicate the big of the file data received
It is small, that is, receive amount of bytes.The variable that variable can be an integer of having downloaded in the present embodiment, is labeled as
SizeDownloaded, for storing downloaded byte amount.When entering OnRecvMessage functions, variable will have been downloaded
The byte that downloaded byte amount in sizeDownloaded is obtained plus the reception amount of bytes in OnRecvMessage functions is total
Number be determined as current byte and.Judge whether file to be downloaded has been downloaded with target sizes information by comparing current byte
At.If current byte and be not equal to target sizes information, update downloaded variable be current byte and, and again call receive
Function and poll methods, to continue to remaining file data;If current byte and be equal to target sizes information, then it represents that wait for
File download is downloaded to complete.
If S140, detecting that download state variable is that pause identifies, stop calling in asynchronous read-write service object
Poll methods.
Wherein, download state variable refers to the variable that can reflect download state, and download state variable may include pause
Mark and recovery mark.Download state variable in the present embodiment can be Boolean variable, or numeric type variable.Pause
It is identified as the pre-set mark for indicating pause and downloading, restores to be identified as the pre-set mark for indicating to restore to download.Show
Example property, if download state variable is Boolean variable, it can indicate pause mark using boolean value true, utilize Boolean
"false" come indicate restore mark.When downloading file to be downloaded according to target response message, download state change can be detected in real time
Amount, can also detect download state variable every preset time.When it is pause mark to detect download state variable, indicate
The HTTP files for stopping downloading are needed, stop calling the poll methods in asynchronous read-write service object at this time, to stop
The download of file.The receiver function in socket in the present embodiment is asynchronous, to need to call in read-write service object
Poll methods carry out event handling.It, will not even if calling the receiver function in socket if stopping calling poll methods
File data is received so that receiving in call back function, to pass through the side for stopping calling the poll methods in read-write service object
Formula realizes the pause function of file download.
Optionally, before S140, further include:
Create a thread, wherein thread is used for recursive call run functions;In run functions, detect in download interface
Download state variable.
Wherein, increase a download state variable in download interface, for indicating whether that pause is downloaded, and connect in download
A thread is created in mouthful, run function of the calling recycled in the thread for file download, and in the run functions, inspection
The download state variable in download interface is surveyed, when download state variable is pause mark, to stop calling read-write service object
In poll methods, so as to suspend at any time to the file of download.
Optionally, this method further includes:
If receiving download pause instruction, the pause function in download interface is called, sets download state variable to
Pause mark;If receiving download restores instruction, the reconstruction in download interface is called, sets download state variable to
Restore mark.
Wherein, it if user wants the HTTP files that pause is downloaded, can be filled to file download by clicking pause button
It sets transmission and downloads pause instruction, when receiving download pause instruction, just call the pause function in download interface, the present embodiment
In pause function be used to set download state variable to pause mark, to suspend connecing to the file data downloaded
It receives.If user wants the HTTP files for restoring to download, it can be sent and be downloaded to file downloading device by click recovery button
Restore instruction, when receiving download recovery instruction, just calls the reconstruction in download interface, the recovery letter in the present embodiment
Number restores mark for setting download state variable to, to continue to download file data.
The technical solution of the present embodiment, by generating target according to the target network address for presetting requesting method and file to be downloaded
Request message, and send destination request message to destination server;In the target response message for receiving destination server transmission
In target response code be success response code when, according to target response message download file to be downloaded;And works as and detect download shape
When state variable is pause mark, stop calling the poll methods in asynchronous read-write service object, to stop receiving text to be downloaded
The data information of part downloads pause function when HTTP files to realize, and can stop the text downloading at any time
Part meets the individual demand of user, and the user experience is improved.
Embodiment two
Fig. 2 is a kind of pause method flow chart of file download provided by Embodiment 2 of the present invention, and the present embodiment is above-mentioned
It is optimized on the basis of each embodiment:After the poll methods in stopping calling read-write service object, further include:If detection
It is to restore to identify to download state variable, then continues to call the poll methods in read-write service object.
The pause method of file download after optimization specifically includes following steps:
S210, the corresponding target network address of file to be downloaded is obtained.
S220, destination request message is generated according to default requesting method and target network address, and mesh is sent to destination server
Mark request message.
S230, the target response message sent according to the destination server of reception determine target response code, if target response
Code is success response code, then enters S240, if target response code is transfer answer code, enters S250.
Wherein, when receiving target response message, target response message is parsed, is determined in destination request message
Target response code.In target response message, started with HTTP version numbers, after HTTP version numbers followed by be exactly target sound
Answer code.Illustratively, if in target response message being " HTTP/1.1 200 ", it is determined that target response code is 200, if target is rung
Answer in message is " HTTP/1.1 302 ", it is determined that target response code is 302.Success response code in the present embodiment can be
200, transfer answer code is 302.When target response code is success response code 200, indicates that destination server is successfully processed and ask
It asks.When target response code is transfer answer code 302, then it represents that redirection mistake has occurred in the target network address of file to be downloaded, i.e.,
Target network address is shifted.
S240, file to be downloaded is downloaded according to target response message, and enter S260.
Wherein, when target response code is success response code, indicate that destination server is successfully processed request, i.e., it is to be downloaded
File does not occur to redirect mistake, directly can download file to be downloaded according to target response message at this time.
S250, transfer network address is determined according to target response message, and target network address is updated according to transfer network address, in update mesh
It marks network address and enters S220 later.
Wherein, when target response code is transfer answer code, show that redirection mistake has occurred, i.e., be according to target network address
File to be downloaded can not be successfully downloaded, needs to determine transfer network address according to target response message at this time.Optionally, target is rung
It answers the Location location fields in header to be parsed, obtains the transfer network address after redirecting.Illustratively, it waits for down
The destination address of published article part version.ini is http://www.douyu.com/pcclient/version.ini, that is, indicate
File to be downloaded version.ini is stored under the pcclient catalogues of this host of www.douyu.com, if because of certain original
File to be downloaded version.ini is moved under pcclient2 catalogues by cause, then the target response header obtained at this time
In Location location fields be " Location:http://www.douyu.com/pcclient2/version.ini ",
It can determine that transfer network address is http according to location field://www.douyu.com/pcclient2/version.ini,
So as to re-download file to be downloaded version.ini according to transfer network address.According to transfer network address update in the present embodiment
Target network address refers to target network address being updated to transfer network address, and be again introduced into S120, so as to according to updated target
Network address updates destination request message, and sends updated destination request message again to destination server, to receive target
The updated target response message that server is sent according to updated destination request message.
If S260, detecting that download state variable is that pause identifies, stop calling in asynchronous read-write service object
Poll methods.
If S270, detecting that download state variable is to restore to identify, continue to call the side poll in read-write service object
Method.
Wherein, after file to be downloaded is suspended, when the download state variable detected is to restore mark, continue to call
The poll methods in service object are read and write, in the receiver function in calling socket, continue using call back function is received
The data information for receiving file to be downloaded, to realize the function of downloading and restore.
The technical solution of the present embodiment, by judging that target response code is to shift answer code or success response code, to
File can be downloaded automatically according to different target response codes, and realized by detecting download state variable to downloading pause
HTTP files restore the function of download.
Embodiment three
Fig. 3 is a kind of structural schematic diagram of the pause device for file download that the embodiment of the present invention three provides, the present embodiment
The case where being applicable to file in pause download server, which includes:Target website acquisition module 310, destination request report
Literary generation module 320, file to be downloaded download module 330 and download pause module 340.
Wherein, target website acquisition module 310, for obtaining the corresponding target network address of file to be downloaded;Destination request report
Literary generation module 320 for generating destination request message according to default requesting method and target network address, and is sent out to destination server
Send destination request message;File to be downloaded download module 330, for receiving in the target response message that destination server is sent
Target response code be success response code when, according to target response message download file to be downloaded;Pause module 340 is downloaded, is used
If in detecting that download state variable is that pause identifies, stop calling the poll methods in asynchronous read-write service object.
Optionally, destination request message generation module 320, including:
Target ip address determination unit, for according to the target domain name addresses in target network address, determine target ip address and
Target port;
Destination server connection unit utilizes asynchronous socket and different for being based on target ip address and target port
Read-write service object's linking objective server of step;
Destination server connection unit, when for the success of linking objective server, according to default requesting method and target network
Location generates destination request message, and sends destination request message to destination server.
Optionally, destination server connection unit is specifically used for:
Create asynchronous read-write service object;Asynchronous socket is created, and read-write service object is passed to socket
Constructed fuction in;The contiguous function of socket is called, and target ip address and target port are passed in contiguous function;According to
Parameter information in connection call back function determine destination server whether successful connection, wherein connection call back function is for receiving
The connection result of contiguous function.
Optionally, it is GET methods to preset requesting method;Correspondingly, destination request message generation unit, is specifically used for:
According to target network address, the heads GET and host head are constructed;According to the heads GET and host head, destination request is determined
Header;According to the transmission function in socket, destination request header is sent to destination server.
Optionally, file to be downloaded download module 330, including:
File destination creating unit, in the predetermined position of disk, create one with it is to be downloaded in target network address
The identical file destination of file name;
Target sizes information determination unit is waited for for the length field information determination in the head according to target response message
Download the target sizes information of file;
File to be downloaded download unit, the side poll in receiver function and read-write service object for calling socket
Method downloads the data information of file to be downloaded according to target sizes information;
Data information writing unit, for being written the data information after downloading into file destination.
Optionally, file to be downloaded download unit is specifically used for:
The poll methods in the receiver function and read-write service object of socket are called, according to connecing in reception call back function
Receive amount of bytes and the downloaded byte amount of having downloaded in variable determine current byte with;
If current byte and be not equal to target sizes information, the downloaded byte amount downloaded in variable is updated to work as
Preceding byte and, and call receiver function and poll methods again;
If current byte and be equal to target sizes information, complete the download of the data information of file to be downloaded.
Optionally, which further includes:
If thread creation module stops calling read-write service for detecting that download state variable is that pause identifies
Before poll methods in object, a thread is created, wherein thread is used for recursive call run functions;
Download state variable detection module, in run functions, to detect the download state variable in download interface.
Optionally, which further includes:
If first download state variable setup module calls for receiving download pause instruction in download interface
Suspend function, sets download state variable to pause mark;
Second download state variable setup module calls if restoring instruction for receiving to download in download interface
Reconstruction sets download state variable to restore mark.
Optionally, which further includes:
Recovery module is downloaded, after the poll methods in stopping calling read-write service object, if detecting download
State variable is to restore to identify, then continues to call the poll methods in read-write service object.
The pause device of above-mentioned file download can perform the pause side for the file download that any embodiment of the present invention is provided
Method has the corresponding function module of pause method and advantageous effect for executing file download.
Example IV
Fig. 4 is a kind of structural schematic diagram for terminal that the embodiment of the present invention four provides.Referring to Fig. 4, which includes:
One or more processors 410;
Memory 420, for storing one or more programs;
When one or more programs are executed by one or more processors 410 so that one or more processors 410 are realized
Such as the pause method for the file download that any embodiment proposes in above-described embodiment.
In Fig. 4 by taking a processor 410 as an example;Processor 410 and memory 420 in terminal can by bus or its
He connects mode, in Fig. 4 for being connected by bus.
Memory 420 is used as a kind of computer readable storage medium, can be used for storing software program, computer can perform journey
Sequence and module, if the corresponding program instruction/module of the pause method of the file download in the embodiment of the present invention is (for example, file
Target website acquisition module 310, destination request message generation module 320, file to be downloaded in the pause device of download are downloaded
Module 330 and download pause module 340).Processor 410 by operation be stored in software program in memory 420, instruction with
And module realizes the pause method of above-mentioned file download to execute various function application and the data processing of terminal.
Memory 420 includes mainly storing program area and storage data field, wherein storing program area can store operation system
Application program needed for system, at least one function;Storage data field can be stored uses created data etc. according to terminal.This
Outside, memory 420 may include high-speed random access memory, can also include nonvolatile memory, for example, at least one
Disk memory, flush memory device or other non-volatile solid state memory parts.In some instances, memory 420 can be into one
Step includes the memory remotely located relative to processor 410, these remote memories can pass through network connection to terminal.On
The example for stating network includes but not limited to internet, intranet, LAN, mobile radio communication and combinations thereof.
The pause method for the file download that the terminal that the present embodiment proposes is proposed with above-described embodiment belongs to same invention structure
Think, the technical detail of detailed description not can be found in above-described embodiment in the present embodiment, and the present embodiment has execution file
The identical advantageous effect of pause method of download.
Embodiment five
The present embodiment five provides a kind of computer readable storage medium, is stored thereon with computer program, which is located
Manage the pause method that the file download as described in any embodiment of the present invention is realized when device executes.
The arbitrary of one or more computer-readable media may be used in the computer storage media of the embodiment of the present invention
Combination.Computer-readable medium can be computer-readable signal media or computer readable storage medium.It is computer-readable
Storage medium can be for example but not limited to:System, device or the device of electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor, or
The arbitrary above combination of person.The more specific example (non exhaustive list) of computer readable storage medium includes:There are one tools
Or the electrical connections of multiple conducting wires, portable computer diskette, hard disk, random access memory (RAM), read-only memory (ROM),
Erasable programmable read only memory (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light
Memory device, magnetic memory device or above-mentioned any appropriate combination.In this document, computer readable storage medium can
With to be any include or the tangible medium of storage program, the program can be commanded execution system, device or device use or
Person is in connection.
Computer-readable signal media may include in a base band or as the data-signal that a carrier wave part is propagated,
Wherein carry computer-readable program code.Diversified forms may be used in the data-signal of this propagation, including but unlimited
In electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer can
Any computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used for
By instruction execution system, device either device use or program in connection.
The program code for including on computer-readable medium can transmit with any suitable medium, including but not limited to:
Wirelessly, electric wire, optical cable, RF etc. or above-mentioned any appropriate combination.
It can be write with one or more programming languages or combinations thereof for executing the computer that operates of the present invention
Program code, described program design language include object oriented program language, such as Java, Smalltalk, C++, also
Including conventional procedural programming language-such as " C " language or similar programming language.Program code can be complete
It executes, partly executed on the user computer on the user computer entirely, being executed as an independent software package, part
Part executes or executes on a remote computer or server completely on the remote computer on the user computer.It is relating to
And in the situation of remote computer, remote computer can pass through the network of any kind, including LAN (LAN) or wide area network
(WAN), it is connected to subscriber computer, or, it may be connected to outer computer (such as led to using ISP
Cross internet connection).
Above-described embodiment serial number is for illustration only, can not represent the quality of embodiment.
Will be appreciated by those skilled in the art that each module of the above invention or each step can use general meter
Device is calculated to realize, they can be concentrated on single computing device, or be distributed in network constituted by multiple computing devices
On, optionally, they can be realized with the program code that computer installation can perform, so as to be stored in storage
It is performed by computing device in device, either they are fabricated to each integrated circuit modules or will be more in them
A module or step are fabricated to single integrated circuit module to realize.In this way, the present invention is not limited to any specific hardware and
The combination of software.
Each embodiment in this specification is described in a progressive manner, the highlights of each of the examples are with
The difference of other embodiment, just to refer each other for the same or analogous part between each embodiment.
Note that above are only presently preferred embodiments of the present invention and institute's application technology principle.It will be appreciated by those skilled in the art that
The present invention is not limited to specific embodiments described here, can carry out for a person skilled in the art it is various it is apparent variation,
It readjusts and substitutes without departing from protection scope of the present invention.Therefore, although being carried out to the present invention by above example
It is described in further detail, but the present invention is not limited only to above example, without departing from the inventive concept, also
May include other more equivalent embodiments, and the scope of the present invention is determined by scope of the appended claims.
Claims (10)
1. a kind of pause method of file download, which is characterized in that including:
Obtain the corresponding target network address of file to be downloaded;
Destination request message is generated according to default requesting method and the target network address, and the target is sent to destination server
Request message;
When it is success response code to receive the target response code in the target response message that the destination server is sent, according to
The target response message downloads the file to be downloaded;
If detecting, download state variable is that pause identifies, and stops calling the poll methods in asynchronous read-write service object.
2. according to the method described in claim 1, it is characterized in that, generating mesh according to default requesting method and the target network address
Request message is marked, and the destination request message is sent to destination server, including:
According to the target domain name addresses in the target network address, target ip address and target port are determined;
Based on the target ip address and the target port, connected with asynchronous read-write service object using asynchronous socket
Destination server;
When connecting the destination server success, destination request report is generated according to default requesting method and the target network address
Text, and send the destination request message to the destination server.
3. according to the method described in claim 2, it is characterized in that, downloading the text to be downloaded according to the target response message
Part, including:
In the predetermined position of disk, a target text identical with the file to be downloaded title in the target network address is created
Part;
The target sizes letter of the file to be downloaded is determined according to the length field information in the head of the target response message
Breath;
The poll methods in the receiver function and the read-write service object of the socket are called, are believed according to the target sizes
Breath downloads the data information of the file to be downloaded;
Data information after download is written into the file destination.
4. according to the method described in claim 3, it is characterized in that, calling the receiver function and read-write clothes of the socket
The poll methods being engaged in object, the data information of the file to be downloaded is downloaded according to the target sizes information, including:
The poll methods in the receiver function and the read-write service object of the socket are called, according in reception call back function
Reception amount of bytes and the downloaded byte amount of having downloaded in variable determine current byte and;
If the current byte and be not equal to the target sizes information, by the downloaded byte amount downloaded in variable
Be updated to the current byte and, and call the receiver function and the poll methods again;
If the current byte and being equal to the target sizes information, under the data information for completing the file to be downloaded
It carries.
If 5. according to the method described in claim 1, it is characterized in that, detect download state variable be pause identify,
Before stopping calling the poll methods in read-write service object, further include:
Create a thread, wherein the thread is used for recursive call run functions;
In the run functions, the download state variable in download interface is detected.
6. according to the method described in claim 1, it is characterized in that, this method further includes:
If receiving download pause instruction, the pause function in download interface is called, sets the download state variable to
Pause mark;
If receiving download restores instruction, the reconstruction in download interface is called, sets the download state variable to
Restore mark.
7. according to any methods of claim 1-6, which is characterized in that the poll in stopping calling read-write service object
After method, further include:
If detecting, the download state variable is to restore to identify, and continues to call the side poll in the read-write service object
Method.
8. a kind of pause device of file download, which is characterized in that including:
Target website acquisition module, for obtaining the corresponding target network address of file to be downloaded;
Destination request message generation module, for generating destination request message according to default requesting method and the target network address,
And send the destination request message to destination server;
File to be downloaded download module, for receiving the target response in the target response message that the destination server is sent
When code is success response code, the file to be downloaded is downloaded according to the target response message;
Pause module is downloaded, if for detecting that download state variable is that pause identifies, stops calling asynchronous read-write service
Poll methods in object.
9. a kind of terminal, which is characterized in that the terminal includes:
One or more processors;
Memory, for storing one or more programs;
When one or more of programs are executed by one or more of processors so that one or more of processors are real
The now pause method of the file download as described in any in claim 1-7.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the program is by processor
The pause method of the file download as described in any in claim 1-7 is realized when execution.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810396744.8A CN108600377B (en) | 2018-04-28 | 2018-04-28 | Method, device, terminal and storage medium for suspending file downloading |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810396744.8A CN108600377B (en) | 2018-04-28 | 2018-04-28 | Method, device, terminal and storage medium for suspending file downloading |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108600377A true CN108600377A (en) | 2018-09-28 |
CN108600377B CN108600377B (en) | 2021-04-27 |
Family
ID=63611005
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810396744.8A Active CN108600377B (en) | 2018-04-28 | 2018-04-28 | Method, device, terminal and storage medium for suspending file downloading |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108600377B (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111142900A (en) * | 2019-12-17 | 2020-05-12 | 深圳市优必选科技股份有限公司 | Program updating method and device and terminal equipment |
CN111756648A (en) * | 2019-03-27 | 2020-10-09 | 百度在线网络技术(北京)有限公司 | Flow congestion control method, device, equipment and medium |
CN112788141A (en) * | 2021-01-18 | 2021-05-11 | 苏州浪潮智能科技有限公司 | File downloading method, device, equipment and computer readable storage medium |
CN112954013A (en) * | 2021-01-27 | 2021-06-11 | 政采云有限公司 | Network file information acquisition method, device, equipment and storage medium |
Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104468363A (en) * | 2013-09-18 | 2015-03-25 | 华为终端有限公司 | Page redirection method, page redirection system, router equipment and terminal equipment |
CN104580285A (en) * | 2013-10-15 | 2015-04-29 | 镇江雅迅软件有限责任公司 | HTTP (hypertext transfer protocol)-based method for realizing continuous file transfer from breakpoints |
CN106027683A (en) * | 2016-07-29 | 2016-10-12 | 乐视控股(北京)有限公司 | File download processing method and device |
US20160373517A1 (en) * | 2006-09-11 | 2016-12-22 | Apple Inc. | Management and Prioritization of Media Items Downloading |
CN106550035A (en) * | 2016-11-04 | 2017-03-29 | 上海斐讯数据通信技术有限公司 | A kind of method of file download terminal and file download |
CN106557584A (en) * | 2016-11-29 | 2017-04-05 | 青岛海信移动通信技术股份有限公司 | A kind of web site collection method and device |
WO2017063189A1 (en) * | 2015-10-16 | 2017-04-20 | Qualcomm Incorporated | Deadline signaling for streaming of media data |
CN107483627A (en) * | 2017-09-12 | 2017-12-15 | 网宿科技股份有限公司 | A kind of file distributing, method for down loading, Distributor, client and system |
CN107749916A (en) * | 2017-08-28 | 2018-03-02 | 深圳市掌星立意科技有限公司 | The method and device that a kind of mobile phone ROM high in the clouds real-time customization is downloaded |
-
2018
- 2018-04-28 CN CN201810396744.8A patent/CN108600377B/en active Active
Patent Citations (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20160373517A1 (en) * | 2006-09-11 | 2016-12-22 | Apple Inc. | Management and Prioritization of Media Items Downloading |
CN104468363A (en) * | 2013-09-18 | 2015-03-25 | 华为终端有限公司 | Page redirection method, page redirection system, router equipment and terminal equipment |
CN104580285A (en) * | 2013-10-15 | 2015-04-29 | 镇江雅迅软件有限责任公司 | HTTP (hypertext transfer protocol)-based method for realizing continuous file transfer from breakpoints |
WO2017063189A1 (en) * | 2015-10-16 | 2017-04-20 | Qualcomm Incorporated | Deadline signaling for streaming of media data |
CN106027683A (en) * | 2016-07-29 | 2016-10-12 | 乐视控股(北京)有限公司 | File download processing method and device |
CN106550035A (en) * | 2016-11-04 | 2017-03-29 | 上海斐讯数据通信技术有限公司 | A kind of method of file download terminal and file download |
CN106557584A (en) * | 2016-11-29 | 2017-04-05 | 青岛海信移动通信技术股份有限公司 | A kind of web site collection method and device |
CN107749916A (en) * | 2017-08-28 | 2018-03-02 | 深圳市掌星立意科技有限公司 | The method and device that a kind of mobile phone ROM high in the clouds real-time customization is downloaded |
CN107483627A (en) * | 2017-09-12 | 2017-12-15 | 网宿科技股份有限公司 | A kind of file distributing, method for down loading, Distributor, client and system |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111756648A (en) * | 2019-03-27 | 2020-10-09 | 百度在线网络技术(北京)有限公司 | Flow congestion control method, device, equipment and medium |
CN111756648B (en) * | 2019-03-27 | 2023-01-17 | 百度在线网络技术(北京)有限公司 | Flow congestion control method, device, equipment and medium |
CN111142900A (en) * | 2019-12-17 | 2020-05-12 | 深圳市优必选科技股份有限公司 | Program updating method and device and terminal equipment |
CN112788141A (en) * | 2021-01-18 | 2021-05-11 | 苏州浪潮智能科技有限公司 | File downloading method, device, equipment and computer readable storage medium |
CN112788141B (en) * | 2021-01-18 | 2022-07-05 | 苏州浪潮智能科技有限公司 | File downloading method, device, equipment and computer readable storage medium |
CN112954013A (en) * | 2021-01-27 | 2021-06-11 | 政采云有限公司 | Network file information acquisition method, device, equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN108600377B (en) | 2021-04-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110221872B (en) | Page jump method and device, electronic equipment and storage medium | |
CN108600377A (en) | A kind of pause method of file download, device, terminal and storage medium | |
CN102904959B (en) | Network accelerating method and gateway | |
CN111062024B (en) | Application login method and device | |
CN107635027B (en) | Domain name resolution method, medium, device and computing equipment | |
CN105939313B (en) | Status code reorientation method and device | |
CN109391673A (en) | A kind of method, system and the terminal device of management update file | |
CN109496418A (en) | Document down loading method, device and equipment/terminal/server | |
CN110011875B (en) | Dial testing method, device, equipment and computer readable storage medium | |
CN114398176A (en) | Service access method, device, electronic equipment and storage medium | |
CN110598135A (en) | Network request processing method and device, computer readable medium and electronic equipment | |
CN113961463A (en) | Application environment switching method and system, storage medium and electronic equipment | |
CN105812481A (en) | Hypertext transfer protocol request identification system and hypertext transfer protocol request identification method | |
CN109873732B (en) | Test method and device for proxy server | |
CN108600378B (en) | File downloading method, device, terminal and storage medium | |
US10594550B2 (en) | Dynamic product installation based on user feedback | |
CN103942277A (en) | Method and device for downloading file in browsers and browsers | |
CN103544209A (en) | Method and system for web page access | |
CN104346460A (en) | Method and device for downloading file and browser client | |
CN104881605B (en) | A kind of webpage redirects leak detection method and device | |
CN105577658B (en) | A kind of method and system for network linking transmission | |
CN114338461A (en) | Network connection monitoring method and related equipment | |
CN114285774A (en) | Flow recording method and device, electronic equipment and storage medium | |
CN110209959B (en) | Information processing method and device | |
CN110311936B (en) | Communication method and device between clients, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |