CN108600377B - Method, device, terminal and storage medium for suspending file downloading - Google Patents

Method, device, terminal and storage medium for suspending file downloading Download PDF

Info

Publication number
CN108600377B
CN108600377B CN201810396744.8A CN201810396744A CN108600377B CN 108600377 B CN108600377 B CN 108600377B CN 201810396744 A CN201810396744 A CN 201810396744A CN 108600377 B CN108600377 B CN 108600377B
Authority
CN
China
Prior art keywords
target
file
downloaded
downloading
download
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.)
Active
Application number
CN201810396744.8A
Other languages
Chinese (zh)
Other versions
CN108600377A (en
Inventor
杨亮
张文明
陈少杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810396744.8A priority Critical patent/CN108600377B/en
Publication of CN108600377A publication Critical patent/CN108600377A/en
Application granted granted Critical
Publication of CN108600377B publication Critical patent/CN108600377B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols 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 method, a device, a terminal and a storage medium for suspending file downloading. The method comprises the following steps: acquiring a target website corresponding to a file to be downloaded; generating a target request message according to a preset request method and a target website, and sending the target request message to a target server; when a target response code in a target response message sent by a target server is received as a successful response code, downloading a file to be downloaded according to the target response message; and if the downloading state variable is detected to be the pause identifier, stopping calling the poll method in the asynchronous read-write service object. According to the technical scheme of the embodiment of the invention, the function of suspending downloading of the HTTP file can be realized, and the user experience is improved.

Description

Method, device, terminal and storage medium for suspending file downloading
Technical Field
The embodiment of the invention relates to a network technology, in particular to a method, a device, a terminal and a storage medium for suspending file downloading.
Background
With the development of network technology, users often download required files in clients. Currently, downloading files in a server based on an HTTP (HyperText Transfer Protocol) network Protocol is one of the most common downloading methods.
Typically, a user may need to pause a file being downloaded while a larger file is being downloaded. However, the HTTP download method in the prior art does not provide the functions of suspending and resuming the download, which affects the user experience.
Disclosure of Invention
The embodiment of the invention provides a method, a device, a terminal and a storage medium for suspending file downloading, so as to realize the function of suspending downloading an HTTP file and improve the user experience.
In a first aspect, an embodiment of the present invention provides a method for suspending file downloading, including:
acquiring a target website corresponding to a file to be downloaded;
generating a target request message according to a preset request method and the target website, and sending the target request message to a target server;
when a target response code in a target response message sent by the target server is received as a successful response code, downloading the file to be downloaded according to the target response message;
and if the downloading state variable is detected to be the pause identifier, stopping calling the poll method in the asynchronous read-write service object.
In a second aspect, an embodiment of the present invention further provides a device for suspending file downloading, including:
the target website acquisition module is used for acquiring a target website corresponding to the file to be downloaded;
the target request message generation module is used for generating a target request message according to a preset request method and the target website and sending the target request message to a target server;
the file downloading module to be downloaded is used for downloading the file to be downloaded according to the target response message when the target response code in the target response message sent by the target server is received as the successful response code;
and the download suspending module is used for stopping calling the poll method in the asynchronous read-write service object if the download state variable is detected to be the suspending identifier.
In a third aspect, an embodiment of the present invention further provides a terminal, where the terminal includes:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of suspending a file download as in any embodiment of the invention.
In a fourth aspect, the embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for suspending file downloading according to any embodiment of the present invention.
According to the embodiment of the invention, a target request message is generated according to a preset request method and a target website of a file to be downloaded, and the target request message is sent to a target server; when a target response code in a target response message sent by a target server is received as a successful response code, downloading a file to be downloaded according to the target response message; and when the downloading state variable is detected to be the pause identification, the poll method in the asynchronous read-write service object is stopped to be called so as to stop receiving the data information of the file to be downloaded, so that the pause function when the HTTP file is downloaded is realized, the file being downloaded can be stopped at any time, the personalized requirement of the user is met, and the user experience is improved.
Drawings
Fig. 1 is a flowchart of a method for suspending a file download according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for suspending file downloading according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a suspension apparatus for downloading a file according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a terminal according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a method for suspending a file download according to an embodiment of the present invention, which is applicable to a case of suspending an HTTP file in a download server. The method may be performed by a suspension means of file downloading, which may be implemented in software and/or hardware, integrated in the client. The method specifically comprises the following steps:
and S110, acquiring a target website corresponding to the file to be downloaded.
The file to be downloaded is an HTTP file which needs to be downloaded from a server by using an HTTP protocol. Each file to be downloaded corresponds to a target website. The target website in this embodiment refers to a URL (Uniform resource Locator) address based on the HTTP protocol. The target website corresponding to the file to be downloaded can be obtained by inputting the website by the user, or by directly clicking the website link corresponding to the file to be downloaded by the user. Illustratively, the name of the file to be downloaded is version.ini, the target website corresponding to the file is HTTP:// www.douyu.com/pcclient/version.ini, wherein www indicates that the protocol of the file version.ini is the HTTP protocol, www.douyu.com indicates the host address, i.e. the domain name address, and pcclient/version.ini indicates the resource path of the file to be downloaded version.ini, and the file to be downloaded version.ini is stored in the pcclient directory of the www.douyu.com host according to the target website.
And S120, generating a target request message according to the preset request method and the target website, and sending the target request message to a target server.
The request methods include, but are not limited to, GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, and CONNECT. The preset request method can be preset according to actual conditions and requirements. Illustratively, the GET request method is typically employed when downloading HTTP files. The target request message may be an HTTP message requesting the target server to download a file. The target server in this embodiment refers to an HTTP server corresponding to the target website, and is configured to receive and respond to the target request packet sent by the file downloading apparatus.
Optionally, S120 includes:
determining a target IP address and a target port according to a target domain name address in a target website; based on the target IP address and the target port, connecting a target server by using an asynchronous socket and an asynchronous read-write service object; and when the target server is successfully connected, generating a target request message according to the preset request method and the target website, and sending the target request message to the target server.
The HTTP Protocol is an upper layer application Protocol based on a TCP (Transmission Control Protocol) Protocol. Generally, the conventional TCP protocol requires a server to be connected according to an IP address and a port, so when a TCP connection is initiated, a target IP address and a target port, for example, an IP address of 127.0.0.1, must be provided. The target website based on the HTTP protocol only provides a domain name address, so that the target domain name address in the target website needs to be resolved, and a target IP address and a target port corresponding to the target domain name address are determined. Optionally, the hostntbyname is called to obtain a host structure, and the target IP address is analyzed according to the h _ addr _ list field in the host structure. Specifically, a target domain name address is transmitted to a gethostbyname function as a parameter through a gethostbyname network API (Application Programming Interface), so as to obtain a host structure data, and according to a h _ addr _ list field in the host structure, an inet _ ntoa is called to obtain h _ addr _ list [0], so that an IP address corresponding to the h _ addr _ list [0] is determined as a target IP address corresponding to the target domain name address. The default port of the HTTP server in this embodiment is 80, so that the target port can be directly determined to be 80. Illustratively, the target website address of the file version.ini to be downloaded is http:// www.douyu.com/pcclient/version.ini, and the target IP address corresponding to www.douyu.com is determined by passing the domain name address www.douyu.com as a parameter into the gethostbyname function. And according to the determined target IP address and the target port, transmitting TCP connection by utilizing a TCP SOCKET and an I/O read-write service object so as to connect the target server.
Optionally, based on the target IP address and the target port, connecting the target server by using an asynchronous socket and an asynchronous read-write service object includes:
establishing an asynchronous read-write service object; creating an asynchronous socket and transmitting a read-write service object into a construction function of the socket; calling a connection function of the socket, and transmitting a target IP address and a target port into the connection function; and determining whether the target server is successfully connected according to the parameter information in the connection callback function, wherein the connection callback function is used for receiving the connection result of the connection function.
In this embodiment, when the target server is connected, an ASIO (asynchronous IO) library of the boost open source library is used. Optionally, an asynchronous read-write service object with a type of boost:: asio:: io _ service is created through the new operator, and the read-write service object may be marked as m _ ioService. And establishing an asynchronous socket with the type of boost:: asio:: ip:: tcp:: socket through a new operational character, and transmitting the established m _ ioService read-write service object into the constructor of the type, wherein the read-write service object can be used as a first parameter of the constructor, and the socket transmitted into the read-write service object can be marked as m _ socket. The target IP address and the target port are imported into a connection function, such as an async _ connect function, in the created socket m _ socket by calling the connection function to connect to the target server. In this embodiment, the connection function of the socket is used to implement asynchronous connection to the target server, and a connection callback function OnConnectResult needs to be provided to determine whether the execution of the connection function is successful, and the connection callback function is used to receive the connection result of the connection function. Optionally, when entering the connection callback function, determining whether the target server is successfully connected by judging whether error parameter information in the connection callback function is equal to 0. If the error parameter information is equal to 0, the connection target server is successful, and if the error parameter information is not equal to 0, the connection target server is failed, and the connection of the target server needs to be performed again.
Optionally, after the target server is successfully connected, a network read data request needs to be initiated to prepare for receiving the response data of the target server. That is, when a receiving function in the socket, such as the async _ read _ some function, is called, an asynchronous request for exclusive rights is posted to the read-write service object. And when the receiving function is called, a receiving callback function OnRecvMessage is also required to be provided to receive the network data sent by the target server. In this embodiment, the receiving function async _ read _ some in the socket is used to implement asynchronous receiving and downloading of the network data sent by the target server.
Optionally, the preset request method is a GET method; correspondingly, generating a target request message according to the preset request method and the target website, and sending the target request message to a target server, wherein the method comprises the following steps:
constructing a GET head and a host head according to a target website; determining a target request message header according to the GET header and the host header; and sending the head of the target request message to the target server according to the sending function in the socket.
After the target server is successfully connected, the target request message can be sent to the target server. When the preset request mode is a GET method, the header data of the HTTP request message of the text type is usually sent to the target server. In the embodiment, the head of the request message needs to use the row break of \ r \ n ', and the tail of the text data has a row break of \ r \ n' without any data. When constructing the GET header, the GET string must be started, followed by the host name in the target web address and the version number of the HTTP protocol. When constructing the Host (Host) header, the Host character string is started, followed by the Host address in the target web address. Illustratively, if the target website address is HTTP:// www.douyu.com/pcclient/version.ini, the constructed GET header is GET pcclient/version.ini HTTP/1.1\ r \ n, and the constructed Host header is Host: www.douyu.com \ r \ n. And adding the constructed host head immediately after the constructed GET head so as to determine the text character string of the target request message head. The text string of the target request message header is sent to the target server by calling a send function in the socket, such as the async _ write _ some function. The sending function async _ write _ some in the socket in this embodiment is used to implement asynchronous sending of the request data.
Optionally, after S120, the method further includes:
and calling a receiving function in the socket, and receiving a target response message sent by the target server by using the receiving callback function.
After the target request message is sent to the target server, if the target server responds successfully, the target server sends a target response message corresponding to the target request message to the file downloading device. In this embodiment, by calling the receiving function async _ read _ some in the socket, when the target server responds successfully, the receiving callback function OnRecvMessage is entered to receive the target response message sent by the target server.
It should be noted that in this embodiment, the connection function async _ connect, the receiving function async _ read _ some, and the sending function async _ write _ some that call a socket are all asynchronous, so that a poll method of a read-write service object needs to be called to process all asynchronous events of the socket.
And S130, when the target response code in the received target response message sent by the target server is a successful response code, downloading the file to be downloaded according to the target response message.
The target response message in this embodiment refers to an HTTP response message generated and sent by the target server according to the target request message. The target response code may be used to describe a request result returned when the request is sent to the target server, and it may be determined whether the target server successfully processes the request or has an error according to the target response code. When receiving the target response message, the method further comprises the following steps: and analyzing the target response message and determining a target response code in the target request message. In the target response message, the HTTP version number is started, and the target response code is immediately followed by the HTTP version number. Illustratively, if the target response message is "HTTP/1.1200", the target response code is determined to be 200, and if the target response message is "HTTP/1.1302", the target response code is determined to be 302. The successful response code in this embodiment may be 200. When the target response code is a successful response code, the target server is indicated to successfully process the request, and the file to be downloaded can be directly downloaded according to the target response message.
Optionally, in S130, downloading the file to be downloaded according to the target response packet includes:
creating a target file with the same name as a file to be downloaded in a target website at a preset position of a magnetic disk; determining target size information of a file to be downloaded according to length field information in a header of a target response message; calling a receiving function of the socket and a poll method in the read-write service object, and downloading data information of the file to be downloaded according to the target size information; and writing the downloaded data information into the target file.
The preset position of the disk refers to a download position of a file to be downloaded, and the preset position can be a storage position in the disk selected by a user in advance according to actual requirements. And analyzing the target website to obtain the file name of the file to be downloaded, such as version. An object file with the same name as the file name, such as a version. Because the target response code in the target response message is a successful response code, Length field information, such as a Content-Length field, must exist in the header of the obtained target response message, and at this time, the target size information of the file to be downloaded is determined according to the Content-Length field. Illustratively, if the obtained Content-Length field is "Content-Length: 1000", it indicates that the target size of the file to be downloaded is 1000 bytes. The target size information in this embodiment may be determined before the target file is created, or may be determined after the target file is created, and the order of the determining step of the target size information and the creating step of the target file is not specifically limited in this embodiment. And calling a receiving function async _ read _ some of the socket and a poll method in the read-write service object, and transmitting target size information into the receiving function async _ read _ some, so that the data information of the file to be downloaded can be received by utilizing a receiving callback function OnRecvMessage. After the data information of the file to be downloaded is downloaded on the target server, the data information of the file to be downloaded is written into the created target file by calling the fwrite function, so that the file to be downloaded is stored.
Optionally, the step of calling a receiving function of the socket and a poll method in the read-write service object, and downloading the data information of the file to be downloaded according to the target size information includes:
calling a receiving function of the socket and a poll method in the read-write service object, and determining the current byte sum according to the receiving byte amount in the receiving callback function and the downloaded byte amount in the downloaded variable; if the current byte sum is not equal to the target size information, updating the downloaded byte quantity in the downloaded variables into the current byte sum, and calling the receiving function and the poll method again; and if the current byte sum is equal to the target size information, finishing the downloading of the data information of the file to be downloaded.
In this embodiment, the receiving function of the socket and the poll method in the read-write service object need to be simultaneously called, so that the receiving callback function receives the file data sent by the target server, and if only the receiving function of the socket is called and the poll method in the read-write service object is not called, the receiving callback function cannot receive the file data. In this embodiment, when the receiving function async _ read _ some and the poll method in the read-write service object are called to receive data, the maximum read size at each time is 8192 bytes, and when the size of the content of the file to be downloaded is larger than 8192 bytes, the async _ read _ some function and the poll method need to be called for many times to complete the downloading of the whole file content. In the receive callback function OnRecvMessage, the first data parameter represents the content of the received file data, and the second size parameter represents the size of the received file data, i.e., the number of received bytes. The downloaded variable in this embodiment may be an integer variable, marked sizewnloaded, for storing the amount of bytes downloaded. When entering the OnRecvMessage function, the total number of bytes obtained by adding the downloaded byte quantity in the downloaded variable sizeDownloaded to the received byte quantity in the OnRecvMessage function is determined as the current byte sum. And judging whether the downloading of the file to be downloaded is finished or not by comparing the current byte with the target size information. If the current byte sum is not equal to the target size information, updating the downloaded variable to be the current byte sum, and calling the receiving function and the poll method again to continue receiving the residual file data; and if the current byte sum is equal to the target size information, the downloading of the file to be downloaded is finished.
S140, if the downloading state variable is detected to be the pause identifier, the poll method in the asynchronous read-write service object is stopped to be called.
The download state variable refers to a variable that can reflect a download state, and the download state variable may include a pause identifier and a resume identifier. The download state variable in this embodiment may be a boolean variable or a numerical variable. The pause mark is a preset mark for representing pause of downloading, and the recovery mark is a preset mark for representing recovery of downloading. For example, if the download state variable is a boolean variable, the pause flag may be represented by a boolean value "true" and the resume flag may be represented by a boolean value "false". When downloading the file to be downloaded according to the target response message, the downloading state variable can be detected in real time, and the downloading state variable can also be detected at preset time intervals. When the download state variable is detected to be the pause identifier, the HTTP file which is being downloaded needs to be stopped, and at the moment, the poll method in the asynchronous read-write service object is stopped to be called, so that the downloading of the file is stopped. In this embodiment, the receiving function in the socket is asynchronous, so that a poll method in the read-write service object needs to be called to perform event processing. If the calling of the poll method is stopped, even if the receiving function in the socket is called, the file data is not received in the receiving callback function, and therefore the pause function of the file downloading is achieved in a mode of stopping calling the poll method in the read-write service object.
Optionally, before S140, the method further includes:
creating a thread, wherein the thread is used for circularly calling a run function; in the run function, a download state variable in the download interface is detected.
The method comprises the steps of adding a downloading state variable in a downloading interface for indicating whether downloading is suspended or not, creating a thread in the downloading interface, circularly calling a run function for downloading a file in the thread, detecting the downloading state variable in the downloading interface in the run function, and stopping calling a poll method in a read-write service object when the downloading state variable is a suspension identifier, so that the downloaded file can be suspended at any time.
Optionally, the method further includes:
if receiving a download pause instruction, calling a pause function in a download interface, and setting a download state variable as a pause identifier; and if the download recovery instruction is received, calling a recovery function in the download interface, and setting the download state variable as a recovery identifier.
If the user wants to suspend the downloaded HTTP file, the user may send a download suspension instruction to the file downloading device by clicking a suspension button, and when the download suspension instruction is received, a suspension function in the download interface is called. If the user wants to recover the downloaded HTTP file, a download recovery instruction may be sent to the file downloading apparatus by clicking a recovery button, and when the download recovery instruction is received, a recovery function in the download interface is called.
According to the technical scheme of the embodiment, a target request message is generated according to a preset request method and a target website of a file to be downloaded, and the target request message is sent to a target server; when a target response code in a target response message sent by a target server is received as a successful response code, downloading a file to be downloaded according to the target response message; and when the downloading state variable is detected to be the pause identification, the poll method in the asynchronous read-write service object is stopped to be called so as to stop receiving the data information of the file to be downloaded, so that the pause function when the HTTP file is downloaded is realized, the file being downloaded can be stopped at any time, the personalized requirement of the user is met, and the user experience is improved.
Example two
Fig. 2 is a flowchart of a suspension method for downloading a file according to a second embodiment of the present invention, where the embodiment performs optimization based on the foregoing embodiments: after the calling of the poll method in the read-write service object is stopped, the method further comprises the following steps: and if the download state variable is detected to be the recovery identifier, continuing to call the poll method in the read-write service object.
The optimized suspension method for file downloading specifically comprises the following steps:
s210, acquiring a target website corresponding to the file to be downloaded.
S220, generating a target request message according to the preset request method and the target website, and sending the target request message to a target server.
And S230, determining a target response code according to the received target response message sent by the target server, if the target response code is a successful response code, entering S240, and if the target response code is a transfer response code, entering S250.
When receiving the target response message, analyzing the target response message, and determining a target response code in the target request message. In the target response message, the HTTP version number is started, and the target response code is immediately followed by the HTTP version number. Illustratively, if the target response message is "HTTP/1.1200", the target response code is determined to be 200, and if the target response message is "HTTP/1.1302", the target response code is determined to be 302. The successful response code in this embodiment may be 200, and the transfer response code is 302. When the target response code is a successful response code 200, it indicates that the target server successfully processed the request. When the target response code is the transfer response code 302, it indicates that the target website of the file to be downloaded has a redirection error, i.e. the target website has been transferred.
S240, downloading the file to be downloaded according to the target response message, and entering S260.
When the target response code is a successful response code, the target server is indicated to successfully process the request, that is, the file to be downloaded has no redirection error, and the file to be downloaded can be directly downloaded according to the target response message.
And S250, determining a transfer website according to the target response message, updating the target website according to the transfer website, and entering S220 after the target website is updated.
When the target response code is the transfer response code, it indicates that a redirection error occurs, that is, the file to be downloaded cannot be successfully downloaded according to the target website, and at this time, the transfer website needs to be determined according to the target response message. Optionally, the Location field in the header of the target response packet is analyzed, and the redirected transfer website is obtained. Illustratively, the target address of the file version.ini to be downloaded is http:// www.douyu.com/pcclient/version.ini, which means that the file version.ini to be downloaded is stored in the pcclient directory of the www.douyu.com host, if the file version.ini to be downloaded is moved to the pcclient2 directory for some reason, the Location field in the header of the target response message acquired at this time is "Location: http:// www.douyu.com/pcclient 2/version.ini", and the transfer address can be determined to be http:// www.douyu.com/pcclient2/version.ini according to the Location field, so that the file version.ini to be downloaded can be re-downloaded according to the transfer address. Updating the target website according to the transfer website in this embodiment means updating the target website to the transfer website, and re-entering S120, so that the target request message may be updated according to the updated target website, and the updated target request message may be re-sent to the target server to receive an updated target response message sent by the target server according to the updated target request message.
And S260, if the downloading state variable is detected to be the pause identifier, stopping calling the poll method in the asynchronous read-write service object.
S270, if the download state variable is detected to be the recovery identifier, continuing to call the poll method in the read-write service object.
After the file to be downloaded is suspended, when the detected download state variable is the recovery identifier, continuing to call the poll method in the read-write service object, so that when a receiving function in the socket is called, the data information of the file to be downloaded is continuously received by using the receiving callback function, and the function of downloading recovery is realized.
According to the technical scheme of the embodiment, the target response code is judged to be the transfer response code or the successful response code, so that the file can be automatically downloaded according to different target response codes, and the downloading resuming function of the HTTP file with the downloading pause is realized by detecting the downloading state variable.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a suspension apparatus for downloading a file according to a third embodiment of the present invention, where the present embodiment is applicable to a case where a file in a download server is suspended, and the apparatus includes: a target website acquisition module 310, a target request message generation module 320, a to-be-downloaded file downloading module 330, and a download pause module 340.
The target website acquiring module 310 is configured to acquire a target website corresponding to a file to be downloaded; a target request message generating module 320, configured to generate a target request message according to a preset request method and a target website, and send the target request message to a target server; the file to be downloaded downloading module 330 is configured to, when receiving that the target response code in the target response message sent by the target server is a successful response code, download the file to be downloaded according to the target response message; the download suspending module 340 is configured to stop calling the poll method in the asynchronous read/write service object if it is detected that the download state variable is the suspension identifier.
Optionally, the target request packet generating module 320 includes:
the target IP address determining unit is used for determining a target IP address and a target port according to a target domain name address in a target website;
a target server connection unit for connecting a target server using an asynchronous socket and an asynchronous read-write service object based on a target IP address and a target port;
and the target server connecting unit is used for generating a target request message according to the preset request method and the target website and sending the target request message to the target server when the target server is successfully connected.
Optionally, the target server connection unit is specifically configured to:
establishing an asynchronous read-write service object; creating an asynchronous socket and transmitting a read-write service object into a construction function of the socket; calling a connection function of the socket, and transmitting a target IP address and a target port into the connection function; and determining whether the target server is successfully connected according to the parameter information in the connection callback function, wherein the connection callback function is used for receiving the connection result of the connection function.
Optionally, the preset request method is a GET method; correspondingly, the target request message generating unit is specifically configured to:
constructing a GET head and a host head according to a target website; determining a target request message header according to the GET header and the host header; and sending the head of the target request message to the target server according to the sending function in the socket.
Optionally, the to-be-downloaded file downloading module 330 includes:
the target file creating unit is used for creating a target file with the same name as a file to be downloaded in a target website at a preset position of the disk;
the target size information determining unit is used for determining the target size information of the file to be downloaded according to the length field information in the header of the target response message;
the file downloading unit to be downloaded is used for calling a receiving function of the socket and a poll method in the read-write service object and downloading the data information of the file to be downloaded according to the target size information;
and the data information writing unit is used for writing the downloaded data information into the target file.
Optionally, the unit for downloading the file to be downloaded is specifically configured to:
calling a receiving function of the socket and a poll method in the read-write service object, and determining the current byte sum according to the receiving byte amount in the receiving callback function and the downloaded byte amount in the downloaded variable;
if the current byte sum is not equal to the target size information, updating the downloaded byte quantity in the downloaded variables into the current byte sum, and calling the receiving function and the poll method again;
and if the current byte sum is equal to the target size information, finishing the downloading of the data information of the file to be downloaded.
Optionally, the apparatus further comprises:
the thread creating module is used for creating a thread before the poll method in the read-write service object is stopped to be called if the download state variable is detected to be the pause identifier, wherein the thread is used for circularly calling a run function;
and the download state variable detection module is used for detecting the download state variable in the download interface in the run function.
Optionally, the apparatus further comprises:
the first download state variable setting module is used for calling a pause function in the download interface and setting the download state variable as a pause identifier if a download pause instruction is received;
and the second download state variable setting module is used for calling a recovery function in the download interface and setting the download state variable as a recovery identifier if a download recovery instruction is received.
Optionally, the apparatus further comprises:
and the download recovery module is used for continuing to call the poll method in the read-write service object after the poll method in the read-write service object is stopped being called and if the download state variable is detected to be the recovery identifier.
The file downloading pause device can execute the file downloading pause method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the file downloading pause method.
Example four
Fig. 4 is a schematic structural diagram of a terminal according to a fourth embodiment of the present invention. Referring to fig. 4, the terminal includes:
one or more processors 410;
a memory 420 for storing one or more programs;
when the one or more programs are executed by the one or more processors 410, the one or more processors 410 are caused to implement the method of suspending a file download as set forth in any of the above embodiments.
In FIG. 4, a processor 410 is illustrated as an example; the processor 410 and the memory 420 in the terminal may be connected by a bus or other means, as exemplified by the bus connection in fig. 4.
The memory 420 is used as a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the suspension method of file downloading in the embodiment of the present invention (for example, the target website acquisition module 310, the target request message generation module 320, the to-be-downloaded file downloading module 330, and the download suspension module 340 in the suspension device of file downloading). The processor 410 executes various functional applications and data processing of the terminal by executing software programs, instructions and modules stored in the memory 420, that is, implements the above-described suspension method of file downloading.
The memory 420 mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system and an application program required by at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 420 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, the memory 420 may further include memory located remotely from the processor 410, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The terminal proposed by the present embodiment and the method for suspending file downloading proposed by the above embodiment belong to the same inventive concept, and the technical details that are not described in detail in the present embodiment can be referred to the above embodiment, and the present embodiment has the same beneficial effects as the method for suspending file downloading.
EXAMPLE five
This fifth embodiment provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the method for suspending a file download according to any of the embodiments of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer-readable storage medium may be, for example but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The above example numbers are for description only and do not represent the merits of the examples.
It will be understood by those skilled in the art that the modules or steps of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and optionally they may be implemented by program code executable by a computing device, such that it may be stored in a memory device and executed by a computing device, or it may be separately fabricated into various integrated circuit modules, or it may be fabricated by fabricating a plurality of modules or steps thereof into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts in the embodiments are referred to each other.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (9)

1. A method for pausing a file download, comprising:
acquiring a target website corresponding to a file to be downloaded;
generating a target request message according to a preset request method and the target website, and sending the target request message to a target server;
when a target response code in a target response message sent by the target server is received as a successful response code, downloading the file to be downloaded according to the target response message;
if the downloading state variable is detected to be the pause identifier, stopping calling the poll method in the asynchronous read-write service object;
the generating a target request message according to a preset request method and the target website and sending the target request message to a target server includes:
determining a target IP address and a target port according to a target domain name address in the target website;
based on the target IP address and the target port, connecting a target server by using an asynchronous socket and an asynchronous read-write service object;
when the target server is successfully connected, generating a target request message according to a preset request method and the target website, and sending the target request message to the target server;
the file to be downloaded is an HTTP file downloaded from the target server by utilizing an HTTP protocol.
2. The method according to claim 1, wherein downloading the file to be downloaded according to the target response packet comprises:
creating a target file with the same name as a file to be downloaded in the target website at a preset position of a magnetic disk;
determining the target size information of the file to be downloaded according to the length field information in the header of the target response message;
calling a receiving function of the socket and a poll method in the read-write service object, and downloading the data information of the file to be downloaded according to the target size information;
and writing the downloaded data information into the target file.
3. The method of claim 2, wherein invoking a receive function of the socket and a poll method in the read/write service object to download the data information of the file to be downloaded according to the target size information comprises:
calling a receiving function of the socket and a poll method in the read-write service object, and determining a current byte sum according to the received byte amount in the receiving callback function and the downloaded byte amount in the downloaded variable;
if the current byte sum is not equal to the target size information, updating the downloaded byte quantity in the downloaded variable into the current byte sum, and calling the receiving function and the poll method again;
and if the current byte sum is equal to the target size information, finishing the downloading of the data information of the file to be downloaded.
4. The method of claim 1, further comprising, before stopping invoking the poll method in the read/write service object if the download status variable is detected as the pause flag:
creating a thread, wherein the thread is used for circularly calling a run function;
and detecting a downloading state variable in a downloading interface in the run function.
5. The method of claim 1, further comprising:
if a download pause instruction is received, calling a pause function in a download interface, and setting the download state variable as a pause identifier;
and if a download recovery instruction is received, calling a recovery function in a download interface, and setting the download state variable as a recovery identifier.
6. The method of any of claims 1-5, further comprising, after stopping the call to the poll method in the read-write service object:
if the download state variable is detected to be the recovery identifier, continuing to call the poll method in the read-write service object.
7. A suspension apparatus for file downloading, comprising:
the target website acquisition module is used for acquiring a target website corresponding to the file to be downloaded;
the target request message generation module is used for generating a target request message according to a preset request method and the target website and sending the target request message to a target server;
the file downloading module to be downloaded is used for downloading the file to be downloaded according to the target response message when the target response code in the target response message sent by the target server is received as the successful response code;
the download suspending module is used for stopping calling the poll method in the asynchronous read-write service object if the download state variable is detected to be the suspending identifier;
the target request message generating module comprises:
a target IP address determining unit, configured to determine a target IP address and a target port according to a target domain name address in a target website;
a target server connection unit, configured to connect a target server using an asynchronous socket and an asynchronous read-write service object based on the target IP address and the target port;
the target server connection unit is used for generating a target request message according to a preset request method and the target website when the target server is successfully connected, and sending the target request message to the target server;
the file to be downloaded is an HTTP file downloaded from the target server by utilizing an HTTP protocol.
8. A terminal, characterized in that the terminal comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the method of suspending a file download of any of claims 1-6.
9. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, is adapted to carry out the method of suspending a file download according to any one of claims 1 to 6.
CN201810396744.8A 2018-04-28 2018-04-28 Method, device, terminal and storage medium for suspending file downloading Active CN108600377B (en)

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 CN108600377A (en) 2018-09-28
CN108600377B true 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)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN112788141B (en) * 2021-01-18 2022-07-05 苏州浪潮智能科技有限公司 File downloading method, device, equipment and computer readable storage medium
CN112954013B (en) * 2021-01-27 2023-04-07 政采云有限公司 Network file information acquisition method, device, equipment and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
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
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7707273B2 (en) * 2006-09-11 2010-04-27 Apple Inc. Management and prioritization of media item downloading

Patent Citations (8)

* Cited by examiner, † Cited by third party
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
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

Also Published As

Publication number Publication date
CN108600377A (en) 2018-09-28

Similar Documents

Publication Publication Date Title
CN108600377B (en) Method, device, terminal and storage medium for suspending file downloading
KR102220127B1 (en) Method and apparatus for customized software development kit (sdk) generation
CN107844324B (en) Client page jump processing method and device
CN109496418B (en) File downloading method and device, and equipment/terminal/server
US11232405B2 (en) Computer readable storage media for dynamic service deployment and methods and systems for utilizing same
CN104219316A (en) Method and device for processing call request in distributed system
CN109391673A (en) A kind of method, system and the terminal device of management update file
CN104504060A (en) File downloading method in browser, browser client side and device
CN108600378B (en) File downloading method, device, terminal and storage medium
CN108494762A (en) Web access method, device and computer readable storage medium, terminal
CN110598135A (en) Network request processing method and device, computer readable medium and electronic equipment
CN115329170A (en) Webpage crawling method, device, equipment and storage medium
CN110324384B (en) Data pushing method and device
CN112015383A (en) Login method and device
CN105677688B (en) Page data loading method and system
CN108370500B (en) Optimized settings for wireless devices
US9754327B2 (en) Method and apparatus for configuring social networking site sharing functions
CN112187869A (en) Remote debugging system and method of IOT device, electronic device and storage medium
CN114338461A (en) Network connection monitoring method and related equipment
CN114666322A (en) Breakpoint resume method and device and electronic equipment
US8527580B2 (en) Saving multiple data items using partial-order planning
CN113132447A (en) Reverse proxy method and system
CN110224973B (en) Multi-server parallel implementation method based on programming game, electronic equipment and medium
CN116933246A (en) Method and device for executing application program in sandbox environment
CN113760564A (en) Data processing method, device and system

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