Disclosure of Invention
The application aims to provide a method and a device for transmitting data between devices, which are used for improving the efficiency of data transmission between the devices.
The application provides a method for transmitting data between devices, which comprises the following steps:
The method comprises the steps of determining a second device for receiving first target data, determining a target transmission mode according to network connection information of the first device and the second device, and transmitting the first target data to the second device through the target transmission mode, wherein the first device is equipment for authentication based on a first account, the second device is equipment for authentication based on a second account, and the first account and the second account are associated accounts.
Optionally, the determining a target transmission mode according to the network connection information of the first device and the second device, and transmitting the first target data to the second device through the target transmission mode includes establishing a first communication connection with the second device and transmitting the first target data to the second device through the first communication connection when the network connection information indicates that the second device and the first device are in the same network domain, wherein the first communication connection is a network connection in a network domain environment, otherwise, the first device transmits the first target data to the second device through a second communication connection established with a server.
Optionally, before the second device for receiving the first target data is determined, the method further comprises the step that after the first device is successfully authenticated with the server through the first account, the second communication connection is established with the server, and the second communication connection is used for data transmission with the server.
Optionally, the determining the second device for receiving the first target data comprises obtaining a device list logged in to the second account from the server, and determining the second device for receiving the first target data from the device list.
Optionally, the method is characterized in that when the network connection information indicates that the second device and the first device are in the same network domain, a first communication connection with the second device is established, and the method comprises the steps of obtaining a first network parameter of the network domain where the second device is located, judging a network connection state with the second device in the network domain environment where the first device is located based on the first network parameter, and establishing the first communication connection with the second device when the first device and the second device have network paths in the network domain environment.
Optionally, after the second communication connection is established with the server, the method further comprises the step of sending a first target information acquisition request to the server based on the first account, wherein the first target information acquisition request is used for acquiring a first Token and a first encryption key corresponding to the first Token, and the first encryption key is used for encrypting the first target data in a data transmission process.
Optionally, before the first target data is transmitted to the second device through the target transmission mode, the method further comprises the steps of sending the first Token to the second device, enabling the second device to obtain the first encryption key from the server based on the first Token and decrypt the encrypted first target data according to the first encryption key, and transmitting the first target data to the second device through the target transmission mode, wherein the step of encrypting the first target data based on the first encryption key and sending the encrypted first target data to the second device through the target transmission mode comprises the steps of.
Optionally, before the first Token is sent to the second device, the method further comprises determining whether the first Token is in a valid period based on the current time of the server, and sending the first Token to the second device if the first Token is in the valid period.
Optionally, after the first Token is sent to the second device, the method further comprises sending a second target information acquisition request to the server based on the first account under the condition that a first Token failure message sent by the second device is received, wherein the second target information acquisition request is used for acquiring a new Token and an encryption key.
Optionally, after the second communication connection is established with the server, the method further comprises the steps of sending a second network parameter of a network domain where the first device is located to the server, wherein the second network parameter is used for judging whether a network access exists between the second device and the first device in a network domain environment based on the second network parameter, and establishing a third communication connection with the first device when the second device and the first device exist in the network domain environment, and the third communication connection is a network connection in the network domain environment.
Optionally, after the second network parameter of the network domain where the first device is located is sent to the server, the method further includes receiving a second Token sent by the second device, and acquiring a second encryption key corresponding to the second Token from the server based on the second Token, where the second encryption key is used for decrypting encrypted data transmitted by the second device to the first device through the third communication connection.
Optionally, after receiving the second Token sent by the second device, the method further comprises determining validity of the second Token based on current time of the server, acquiring a second encryption key corresponding to the second Token from the server based on the second Token, wherein the second encryption key corresponding to the second Token is acquired from the server based on the second Token when the second Token is in the validity period, and otherwise, sending a second Token failure message to the second device, wherein the second Token failure message is used for indicating the second device to acquire the Token again to the server.
Optionally, after the second communication connection is established with the server, the method further comprises the steps of receiving a message queue sent by the server, generating a receiving sequence according to the sending sequence of the messages in the message queue, and obtaining the data to be transmitted corresponding to the messages in the message queue from the server according to the receiving sequence and the data identification of the data to be transmitted corresponding to the messages in the message queue in the server, wherein the message queue is generated based on the sending time of the data contained in the second target data sent by the second device when the first device is in an offline state.
The method comprises the steps of receiving first target data transmitted by a server, transmitting the first target data to a second device according to a target transmission mode, wherein the first target data is transmitted to the second device according to the target transmission mode, the second device comprises data information of the first target data, and receiving blocking information of the first target data, which is transmitted by the server according to the data information, wherein the blocking information comprises the number of data blocks corresponding to the first target data and the number corresponding to each data block, dividing the first target data into at least one data block according to the blocking information, the number of the at least one data block is the same as the number of the data blocks, acquiring the number corresponding to the unfinished target data block in the at least one data block under the condition that transmission interruption occurs in the process of transmitting the first target data to the server by the first device, and after the first device and the server reestablish communication connection, retransmitting the target data block to the server according to the number corresponding to the target data block.
The application also provides a device for transmitting data between devices, which comprises:
The system comprises a determining module, a data transmission module, a target transmission mode determining module and a correlation module, wherein the determining module is used for determining second equipment for receiving first target data, the data transmission module is used for determining a target transmission mode according to network connection information of the first equipment and the second equipment and transmitting the first target data to the second equipment through the target transmission mode, the first equipment is equipment for authenticating based on a first account, the second equipment is equipment for authenticating based on a second account, and the first account and the second account are correlation accounts.
Optionally, the data transmission module is specifically configured to establish a first communication connection with the second device and transmit the first target data to the second device through the first communication connection when the network connection information indicates that the second device and the first device are in the same network domain, where the first communication connection is a network connection in a network domain environment, and otherwise, the first device transmits the first target data to the second device through a second communication connection established with a server.
Optionally, the device further comprises a communication connection module, wherein the communication connection module is used for establishing the second communication connection with the server after the first equipment is successfully authenticated with the server through the first account, and the second communication connection is used for data transmission with the server.
Optionally, the device further comprises an acquisition module, a determination module and a determining module, wherein the acquisition module is used for acquiring a device list logged in the second account from the server, and the determining module is specifically used for determining a second device for receiving the first target data from the device list.
The communication connection module is specifically configured to determine a network connection state with the second device in a network domain environment based on the first network parameter, and the communication connection module is specifically configured to establish a first communication connection with the second device when a network path exists between the first device and the second device in the network domain environment.
The device comprises a server, a sending module and a target information acquisition module, wherein the sending module is used for sending a first target information acquisition request to the server based on the first account, the first target information acquisition request is used for acquiring a first Token and a first encryption key corresponding to the first Token, and the first encryption key is used for encrypting first target data in a data transmission process.
Optionally, the sending module is further configured to send the first Token to the second device, so that the second device obtains the first encryption key from the server based on the first Token and decrypts the encrypted first target data according to the first encryption key, and the data transmission module is specifically configured to encrypt the first target data based on the first encryption key and send the encrypted first target data to the second device in the target transmission mode.
Optionally, the determining module is further configured to determine whether the first Token is in a validity period based on a current time of the server, and the sending module is further configured to send the first Token to the second device if the first Token is in the validity period.
Optionally, the sending module is further configured to send, based on the first account, a second target information acquisition request to the server when the receiving module receives the first Token invalidation message sent by the second device, where the second target information acquisition request is used to acquire a new Token and an encryption key.
Optionally, the sending module is further configured to send a second network parameter of a network domain where the first device is located to the server, where the second network parameter is used by the second device to determine whether a network path exists with the first device in a network domain environment based on the second network parameter, and establish a third communication connection with the first device when the second device and the first device have the network path in the network domain environment, and the third communication connection is a network connection in the network domain environment.
The receiving module is further configured to receive a second Token sent by the second device, and the obtaining module is further configured to obtain, from the server, a second encryption key corresponding to the second Token based on the second Token, where the second encryption key is used to decrypt encrypted data that is transmitted by the second device to the first device through the third communication connection.
Optionally, the determining module is further configured to determine validity of the second Token based on a current time of the server, and the acquiring module is specifically configured to acquire, based on the second Token, a second encryption key corresponding to the second Token from the server if the second Token is within a validity period, and otherwise, send a second Token failure message to the second device, where the second Token failure message is used to instruct the second device to acquire the Token again from the server.
The server is used for receiving the message queue sent by the server, generating a receiving sequence according to the sending sequence of the message in the message queue, and acquiring the data to be transmitted corresponding to the message in the message queue from the server according to the receiving sequence and the data identification of the data to be transmitted corresponding to the message in the message queue in the server, wherein the message queue is generated based on the sending time of each data contained in the second target data sent by the second device when the first device is in an offline state.
The device comprises a server, a file dividing module, a receiving module, a sending module and an obtaining module, wherein the sending module is used for sending data information of first target data to the server, the receiving module is used for receiving block information of the first target data sent by the server based on the data information, the block information comprises the number of data blocks corresponding to the first target data and a number corresponding to each data block, the file dividing module is used for dividing the first target data into at least one data block based on the block information, the number of the at least one data block is the same as the number of the data blocks, the obtaining module is used for obtaining the number corresponding to the unfinished target data block in the process that the first device transmits the first target data to the server when transmission interruption occurs, and the sending module is used for re-sending the target data block to the server according to the number corresponding to the target data block after the first device re-establishes communication connection with the server.
The application also provides a computer program product comprising computer programs/instructions which when executed by a processor implement the steps of a method of transferring data between devices as described in any of the above.
The application also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of a method of transferring data between devices as described in any of the above when the program is executed.
The application also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of a method of transferring data between devices as described in any of the above.
After a second device for receiving first target data is determined, a first device determines a target transmission mode according to network connection information of the first device and the second device, and transmits the first target data to the second device through the target transmission mode. When data transmission is carried out between the devices, a more appropriate data transmission mode can be selected based on the network connection information of the devices, so that the data transmission efficiency between the devices is improved. And when transmission interruption occurs and transmission is carried out again, continuous transmission can be carried out based on the number of the data block which is not transmitted and is corresponding to the first target data, repeated transmission of the data block which is transmitted and is completed is not needed, and the transmission efficiency is greatly improved.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged, as appropriate, such that embodiments of the present application may be implemented in sequences other than those illustrated or described herein, and that the objects identified by "first," "second," etc. are generally of a type, and are not limited to the number of objects, such as the first object may be one or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
The method for transmitting data between devices provided by the embodiment of the application is described in detail below through specific embodiments and application scenarios thereof with reference to the accompanying drawings.
As shown in fig. 1, a method for transmitting data between devices according to an embodiment of the present application may include the following steps 101 and 102:
step 101, determining a second device for receiving the first target data.
The first device is a device for authentication based on a first account, the second device is a device for authentication based on a second account, and the first account and the second account are associated accounts.
The first account and the second account may be the same account or different accounts. The first account and the second account can be associated with each other when the first account and the second account are the same account, the first device and the second device are devices based on authentication of the same account, and the first account and the second account can be associated with each other when the first account and the second account are different accounts. For example, the second account and the first account may be a friend relationship, where the friend relationship may be understood as an account that has been authenticated and communicated, or the second account may be an account that has been authorized by the first account.
In an exemplary case that the first account and the second account are different accounts, after the user logs in the first account on the first device, the second account associated with the first account may be acquired from the server, and further, the second device logged in with the second account may be acquired. When the first account and the second account are the same account, after the user logs in the first account on the first device, the second device logged in with the first account can be obtained from the server.
Illustratively, the account can be logged in a plurality of ways, including any login form including by a user name password, a mobile phone number, a WeChat, etc.
For example, when a user of a first device wants to send first target data to a second device, the second device may be selected from a list of devices displayed on the first device. The first device may also determine a second device for receiving the first target data according to the set program.
The first target data may be, for example, a file, an image, a video, or the like.
Step 102, determining a target transmission mode according to the network connection information of the first device and the second device, and transmitting the first target data to the second device through the target transmission mode.
The network connection information is used to indicate whether the first device and the second device are within the same network domain.
For example, when the first device and the second device are in the same network domain, the transmission may be performed by the first transmission mode, and when the first device and the second device are not in the same network domain, the transmission may be performed by the second transmission mode.
It should be noted that, after determining the above-mentioned target transmission mode, the second device may also transmit data to the first device through the target transmission mode.
The target transmission method may be a transmission method transferred by a server, that is, the first transmission method, or may be a method in which the first device and the second device directly transmit, that is, the second transmission method.
For example, the first device may transmit the first target data to the server, after which the server notifies the second device of the information such as the path or identity of its first target data stored on the server. The second device obtains the first target data from the server based on the path or the identification.
For example, if the first device and the second device are in the same network domain, the first device may establish a peer-to-peer communication connection with the second device, and further transmit the first target data to the second device through the communication connection.
It can be understood that, when the devices in the same network domain perform data transmission, the method has the advantages of high transmission speed, less influence of network fluctuation and no consumption of traffic, so that the first device and the second device can perform data transmission in a point-to-point mode preferentially under the condition that the first device and the second device are in the same network domain.
In this way, after determining the second device for receiving the first target data, the first device determines a target transmission mode according to the network connection information of the first device and the second device, and transmits the first target data to the second device through the target transmission mode. When data transmission is carried out between the devices, a more appropriate data transmission mode can be selected based on the network connection information of the devices, so that the data transmission efficiency between the devices is improved.
Alternatively, in the embodiment of the present application, the data transmission manner between the first device and the second device may be specifically determined in the following manner.
Illustratively, the step 102 may include the following steps 102a1 and 102a2:
Step 102a1, when the network connection information indicates that the second device and the first device are in the same network domain, establishing a first communication connection with the second device, and transmitting first target data to the second device through the first communication connection.
Wherein the first communication connection is a network connection in a network domain environment. I.e. a point-to-point communication connection established by a first device and a second device within the same network domain.
The network domain environment may include a specific intranet environment, for example, a lan environment, a network environment formed by a virtual private network (Virtual Private Network, VPN), and the like. The communication speed between the devices in the network environment is high, or the communication safety is guaranteed.
Step 102a2, otherwise, transmitting the first target data to the second device through a second communication connection established between the first device and the server.
For example, the first device may obtain network connection information with the second device, and determine whether the first device and the second device are within the same network domain based on the network connection information. If yes, the data is transmitted through the point-to-point connection, and if not, the data can be transmitted to the second equipment in a transfer mode of the server.
The first device may, for example, establish a second communication connection with the server, in particular by means of the following step 103:
step 103, after the authentication of the first device and the server is successful through the first account, the first device establishes a second communication connection with the server.
Wherein the second communication connection is used for data transmission with the server.
The first device establishes the second communication connection with the server after successfully authenticating the first account after logging in. The second communication connection is used for communication and data transmission between the first device and the server.
For example, after the first device establishes the second communication connection with the server, the first device may obtain, based on the first account, an account list having an association relationship with the first account, and select a second account from which data transmission is required.
It may be appreciated that the account list may include an account having an association relationship with the first account, and may further include device information corresponding to each account. The user may select based on the device information or may select based on an account.
Illustratively, the step 101 may include the following steps 101a1 and 101a2:
Step 101a1, obtaining a device list logged into the second account from the server.
Step 101a2, determining a second device receiving the first target data from the device list.
Illustratively, after determining the second device that receives the first target data, the first device may specifically determine whether the first device and the second device are within the same network domain by following steps 104 through 106:
step 104, obtaining a first network parameter of a network domain where the second device is located.
Step 105, based on the first network parameter, judging the network connection state of the second device in the network domain environment where the first device is located.
And step 106, under the condition that the first equipment and the second equipment have network paths in the network domain environment, establishing first communication connection with the second equipment.
Wherein the first network parameter comprises at least one of a network domain internet protocol (internet protocol, IP) address, port number of the second device.
For example, the first device may obtain the first network parameter of the second device from the server after determining the second device for receiving the first target data. The first network parameter is sent to the server based on the network domain parameter of the second device after the second device and the server are successfully authenticated.
For example, after acquiring the first network parameter, the first device may test whether a network path exists with the second device in the network domain environment according to the first network parameter.
Illustratively, the first device may obtain the domain IP address of the second device, and then test whether communication between the first device and the domain IP address is enabled by a Ping (PACKET INTERNET Groper, internet packet explorer) command. If so, the first device and the second device are in the same network domain, and point-to-point connection can be established. If not, the first device and the second device are not in the same network domain or in the same network domain, but cannot communicate.
The first device may also test whether communication between the first device and the domain IP address is possible through a Telnet command according to the domain IP address of the second device and the port number opened by the second device.
As shown in fig. 2, device a, after establishing a message channel with the cloud server, may register device capabilities with the device service, which may include the device receiving offline messages, processor capabilities, and so on. The network parameters of the device a, which are mainly network parameters of the intranet of the device a, for example, the intranet IP address of the device a, etc., are then sent to the server. The network parameters of the equipment A are mainly used for judging whether the data transmitting end and the equipment A are in the same network domain or not when the equipment A is a data receiving end. And after the device A is online, the message service records the online state, and then notifies the other account logged-in devices which have association relation with the account of the device A, and the device state is updated by the other account logged-in devices.
Referring to fig. 2, as shown in fig. 3, when the device B needs to send data to the device a, the network parameter sent by the device a to the server may be obtained from the server, and based on the network parameter, it is determined whether the device a is in the same network domain, if so, the device B is transmitted to the device a through the cloud server, and if not, the device B is directly transmitted to the device a.
Optionally, in the embodiment of the present application, after the first device logs in the first account, if it wants to transmit data to the second device through the first transmission manner, in order to ensure the security of the data, the data needs to be encrypted.
Exemplary after the step 103, the method for transmitting data between devices provided in the embodiment of the present application may further include the following step 107:
Step 107, based on the first account, a first target information acquisition request is sent to a server.
The first target information obtaining request is used for obtaining a first Token and a first encryption key corresponding to the first Token. The first encryption key is used for encrypting the first target data in the data transmission process.
The first target information may include, for example, a first Token and a first encryption key corresponding to the first Token. The first encryption key is used to encrypt the first target data.
It can be understood that, because all the requests of the client are processed by the server, the number of the requests to be processed by the server is huge, so in order to avoid that the client frequently sends request data to the server when the file is encrypted and transmitted, in the embodiment of the application, a Token mechanism is introduced. The Token refers to that the client frequently requests data, the server frequently goes to the database to inquire the user name and the password, compares the user name and the password, judges whether the user name and the password are correct or not, and gives out corresponding prompts.
The Token is a string of character strings generated by the server and is used as a Token for the client to request, after the first login, the server generates a Token and returns the Token to the client, and the client only needs to carry the Token to request data, and does not need to carry a user name and a password again. By introducing Token in the encryption transmission process, the pressure of the server can be reduced to a certain extent, frequent database query is reduced, and the server is more robust.
The first Token is the identity authentication information of the first device, so that the first device is prevented from frequently applying authentication to the server, and the processing load of the server is reduced. Meanwhile, the first Token can also be used for other devices as authorized devices of the first device, and information related to the first device, such as an encryption key, is obtained from a server.
Illustratively, the first device, after acquiring the first Token and the first encryption key, may encrypt the transmitted data using the encryption key. The data receiving end can acquire the encryption key from the server through the first Token, so that sensitive data is prevented from being leaked in the transmission process.
Illustratively, before the step 102, the method for transmitting data between devices according to the embodiment of the present application may further include the following step 108:
Step 108, the first Token is sent to the second device, so that the second device obtains the first encryption key from the server based on the first Token, and decrypts the encrypted first target data according to the first encryption key.
The first device may send the first Token to the second device through the first communication method and the second communication method, or may send the first Token to the second device through another communication connection established with the second device. In the embodiment of the present application, the manner in which the first device sends the Token to the second device is not limited.
Illustratively, the step 102 may specifically include the following step 102b1.
Step 102b1, encrypting the first target data based on the first encryption key, and transmitting the encrypted first target data to the second device in the target transmission mode.
The first device may send the encrypted first target data to the second device through any one of the first communication connection and the second communication connection according to the network condition after sending the first Token to the second device.
Illustratively, as a receiving end of the encrypted first target data, the second device needs to have a capability of decrypting the encrypted data, where the decryption capability may be obtained by the first Token obtaining the corresponding encryption key from the server.
Illustratively, the second device may obtain the first encryption key from the server based on the Token and the account of the second device after obtaining the first Token. The first encryption key may also be used to decrypt data encrypted by the first encryption key.
For example, as shown in fig. 4, when device a initially transmits data to device B, and device a is within the same network domain as device B. Device a needs to obtain Token and key from the cloud server based on the logged-in account. The Token is then sent to device B via the near field communication capability established with device B (i.e. the first communication connection described above). After receiving the Token, the device B obtains the key corresponding to the Token (i.e., the first encryption key) from the server based on the account in which the device logs. After the device B successfully acquires the key, it informs the device a that the device can encrypt the data using the key and transmit the encrypted data to the device B.
For example, in order to guarantee data security, the server will typically set a validity period for each Token, so the first device needs to verify whether the first Token is within the validity period before sending the first Token to the second device.
It will be appreciated that Token can only obtain the corresponding encryption key from the server based on Token if it is within a validity period. Here, the expiration date may be understood as setting a period of time during which the Token can be used, or may be understood as setting a period of time with a period of time limitation between a certain server or a certain device.
Illustratively, before the step 108, the method for transmitting data between devices provided in the embodiment of the present application may further include the following steps 109 and 110:
step 109, determining whether the first Token is within the validity period based on the current time of the server.
Step 110, in the case that the first Token is within the validity period, sending the first Token to the second device.
Illustratively, the first device may verify, via the server, whether the first Token is within a validity period.
It will be appreciated that the first device, upon retrieving the first Token from the server, the server records the current time and sets a validity period during which the device may retrieve the first encryption key via the first Token. The validity period of the first Token is calculated based on the server time, and therefore, it is necessary to determine whether the first Token is within the validity period based on the current time of the server. When the first Token expires, the first encryption key also expires.
For example, if the first Token is within the validity period, the first device may send the first Token to the second device for the second device to obtain the first encryption key. The first device does not need to repeatedly acquire the Token when the first Token is within the validity period.
For example, if the first device sends a first Token, the first Token is in the validity period, but after the second device receives the first Token, the first Token has failed, the second device returns a Token failure message to prompt the first device to reacquire the Token.
Exemplary, after the step 108, the method for transmitting data between devices provided in the embodiment of the present application may further include the following step 111:
Step 111, under the condition that a first Token invalidation message sent by the second device is received, sending a second target information acquisition request to the server based on the first account.
Wherein the second target information obtaining request is used for obtaining a new Token and an encryption key.
Illustratively, the first device needs to acquire the Token from the server again after receiving the Token invalidation message sent by the second device, for later data transmission.
For example, as shown in fig. 5, a flowchart of the operation after the device authentication Token fails is shown. Before device a sends a Token to device B, it needs to verify to the server whether the Token is valid, and if so, send the Token to device B via the near field communication capability established with device B. After receiving the Token, the device B also needs to verify the validity of the Token with the server, so as to avoid that the received encrypted data cannot be decrypted. If the server returns Token past information, device B needs to notify device a that the Token has failed, and device a needs to retrieve the new Token and encryption key from the server again.
Optionally, in the embodiment of the present application, the first device may be used not only as a data sending end but also as a data receiving end, to receive data sent by the second device.
It should be noted that the first device and the second device have the same functions and roles, and the feature description for the first device may be applied to the second device, and the feature description for the second device may also be applied to the first device.
For example, when the first device is used as the data receiving end, after the step 103, the method for transmitting data between devices according to the embodiment of the present application may further include the following step 112:
Step 112, sending the second network parameter of the network domain where the first device is located to the server.
The second network parameter is used for judging whether a network path exists between the second device and the first device in the network domain environment based on the second network parameter, and establishing third communication connection with the first device under the condition that the second device and the first device exist the network path in the network domain environment. The third communication connection is a network connection in a network domain environment.
In an exemplary embodiment, after the first device establishes a communication connection with the server, the first device sends a second network parameter to the server, where the second device determines whether the first device is in the same network domain when the second device is used as a data receiving end of the second device.
For example, after the step 112, the method for transmitting data between devices provided in the embodiment of the present application may further include the following steps 113 and 114:
step 113, receiving a second Token sent by the second device.
Step 114, based on the second Token, obtaining a second encryption key corresponding to the second Token from the server.
Wherein the second encryption key is used to decrypt encrypted data transmitted by the second device to the first device over the third communication connection.
The first device, as a data receiving end, is capable of receiving the second Token sent by the second device, after the first device is in the same network domain as the second device and a third communication connection is established, which indicates that the second device needs to send data to the first device.
Illustratively, after receiving the second Token, the first device may obtain, from the server, a second encryption key corresponding to the second Token, based on the second Token, where the second encryption key is used to decrypt second target data sent by the second device.
Illustratively, the first device, as the data receiving end, also needs to verify the validity of the second Token with the server after receiving the second Token.
Illustratively, after step 113, the method for transmitting data between devices according to the embodiment of the present application may further include the following step 115:
Step 115, determining the validity of the second Token based on the current time of the server.
Illustratively, the above step 114 may include the following steps 114a and 114b:
Step 114a, when the second Token is within the validity period, acquiring a second encryption key corresponding to the second Token from the server based on the second Token.
Step 114b, otherwise, sending a second Token invalidation message to the second device.
The second Token invalidation message is used for indicating the second equipment to acquire the Token from the server again.
For example, if the second Token is within the validity period, a second encryption key corresponding to the second Token may be acquired from the server. If the second Token has been invalidated, a second Token invalidation message needs to be sent to the second device, and the second device acquires the new Token and the encryption key from the server again after receiving the second Token invalidation message.
Optionally, in the embodiment of the present application, when the first device is used as the data receiving end and the first device is in an offline state, after the first device is online again, the server may sequentially obtain, from the server, the data received when the first device is in the offline state, according to a message queue generated by the server according to the time of sending the data.
Exemplary, after the step 103, the method for transmitting data between devices provided in the embodiment of the present application may further include the following steps 116 and 117,
Step 116, receiving a message queue sent by the server.
Step 117, generating a receiving sequence according to the sending sequence of the messages in the message queue, and acquiring the data to be transmitted corresponding to the messages in the message queue from the server according to the receiving sequence and the data identification of the data to be transmitted corresponding to the messages in the message queue in the server.
When the first device is in an offline state, the server generates the message queue based on the sending time of the data contained in the second target data sent by the second device.
The server may send a message queue generated by the second target data sent by the second device when the first device is offline to the first device, for example, after the first device is re-online. The first device may obtain, in turn, data corresponding to each message in the message queue from the server based on the message queue.
Each message in the message queue may include one complete second target data, or may include a part of the second target data when the data is larger.
For example, the second target data may include a plurality of sub-data, and each message in the message queue may correspond to one sub-data. The first device determines a receiving order according to the transmission time of each sub-data in the message queue, and receives each sub-data according to the receiving order.
Illustratively, after the second device transmits the second target data to the server, the server stores the second target data and generates the corresponding data identification. The first device may obtain the second target data from the server based on the data identification.
Illustratively, the step 117 may include the following step 117a:
Step 117a, based on the data identifier of the data to be transmitted corresponding to each message in the message queue in the server, obtaining the data to be transmitted from the server.
The second target data may be sent by the second device in one data transmission process, or may be sent by the second device in multiple data transmission processes.
The server generates the message queue based on the transmission time of each of the second target data transmitted by the second device. The first device determines a receiving sequence of each data to be transmitted based on the sending time of each message corresponding to the data to be transmitted in the message queue, and receives the data to be transmitted according to the receiving sequence.
Optionally, in the embodiment of the present application, in order to ensure stability of data transmission, when a client transmits data to a server, the transmitted data is blocked and numbered, so that when the data transmission is repeated, the data which is not transmitted completely can be continuously transmitted, without repeating the transmission of the data which is transmitted completely, due to transmission interruption caused by a user or a network and the like in the data transmission process.
Illustratively, the step 102 may include the following steps 102c1 to 102c4:
Step 102c1, transmitting data information of the first target data to the server, and receiving block information of the first target data transmitted by the server based on the data information.
The partitioning information comprises the number of data blocks corresponding to the first target data and the number corresponding to each data block.
Illustratively, the data information may include a data size, a file name, and the like of the first target data. The server determines the blocking information of the first target data according to the data size of the first target data, wherein the blocking information can comprise the number of data blocks, the size and the number of each data block. And then, the server sends the blocking information to the first device, and the first device blocks the first target data based on the blocking information after receiving the blocking information.
Specifically, the server may determine the number of blocks according to the state of the current network connection with the first device. The better the current network connection state is, the fewer the number of blocks is, and the worse the current network connection state is, the more the number of blocks is.
It can be understood that when the connection state of the current network is good, the stability of data transmission can be ensured, larger files can not be transmitted, when the connection state of the current network is poor, the probability of error occurrence in the transmission process is increased, at the moment, the size of each data block is reduced, and when the error occurs, the data quantity required to be retransmitted is also less.
Step 102c2, dividing the first target data into at least one data block based on the block information.
Wherein the number of at least one data block is the same as the number of data blocks.
Step 102c3, obtaining a number corresponding to the target data block which is not transmitted in at least one data block when transmission interruption occurs in the process of transmitting the first target data to the server by the first device.
Step 102c4, after the first device reestablishes the communication connection with the server, the target data block is sent to the server again according to the number corresponding to the target data block.
Illustratively, when the first device sends the first target data to the server, the first device receives the information of the remaining number of data blocks and the information of the remaining size of the data blocks sent by the server, and indicates the number of data blocks currently not yet transmitted and the remaining size of the data blocks currently being transmitted. And when the residual number of the data blocks and the residual size of the data blocks are 0, indicating that all the data blocks in the at least one data block are transmitted. At this time, the first device may transmit transmission completion information to the server, and after the server receives the transmission completion information,
For example, if the transmission process is interrupted due to a user or a network during the transmission process, after the transmission channel is re-established, the breakpoint continuous transmission may be performed according to the number of the data block.
Illustratively, after the first device sends the data information of the first target data to the server, the first device receives the chunk information of the first target data sent by the server. The blocking information may include at least one of a data ID corresponding to the first target data, the number of data blocks corresponding to the first target data, and a number corresponding to each data block.
In an exemplary embodiment, when the first device transmits the first target data, the first device records the number corresponding to the data block that has completed transmission, and when the transmission process is interrupted and the transmission is performed again, the data block that has not completed transmission may be directly transmitted according to the number corresponding to the data block that has not completed transmission, without repeating the transmission of the data block that has completed transmission.
When the first device transmits the first target data to the server, the server allocates a corresponding data ID to the first target data, and when the first target data is transmitted continuously, the server can splice the retransmitted data block with the previously transmitted data block based on the data ID.
For example, taking uploading and downloading of a file to a server by a device a as an example, the device a obtains a file ID, a partition number and a partition size by starting an uploading interface when uploading the file, the server determines the cutting number according to the file size, if the file is smaller, only one partition can be provided, and the device a cuts the file according to the partition number and the partition number returned by the server. When the file is uploaded, the device A calls the uploading interface to finish the uploading, so that the server can synthesize all the blocks into one block, and at the moment, after the device B receives the file information, the device B can download the file through the downloading interface, the principle is similar to uploading, the file is cut through the block downloading in the interface, and when the returned block numbers and the block sizes are all 0, the file downloading is finished.
According to the method for transmitting data among the devices, which is provided by the embodiment of the application, the data can be transmitted among the devices, the faster data transmission can be selected from a server transfer transmission mode or a near field communication setting mode based on the network state information among the devices, the technical problems that the existing file transmission method, transmission device and transmission system are influenced by factors of hardware devices or the transmission speed is slower are solved, and the data encryption and decryption provided by the embodiment of the application can effectively guarantee the safety during transmission. And when transmission interruption occurs and transmission is carried out again, continuous transmission can be carried out based on the number of the data block which is not transmitted and is corresponding to the first target data, repeated transmission of the data block which is transmitted and is completed is not needed, and the transmission efficiency is greatly improved.
It should be noted that, in the method for transmitting data between devices provided in the embodiment of the present application, the execution body may be a device for transmitting data between devices, or a control module in the device for transmitting data between devices, where the control module is used for executing the method for transmitting data between devices. In the embodiment of the present application, a method for executing data transmission between devices by using a device for transmitting data between devices is taken as an example, and the device for transmitting data between devices provided in the embodiment of the present application is described.
In the embodiment of the present application, the method is shown in the drawings. The method of transmitting data between devices is described by way of example in connection with one of the drawings in the embodiments of the present application. In specific implementation, the method for transmitting data between devices shown in the foregoing method drawings may also be implemented in combination with any other drawing that may be combined and is illustrated in the foregoing embodiment, which is not repeated herein.
The apparatus for transmitting data between devices provided by the present application will be described below, and the method for transmitting data between devices described below and the method for transmitting data between devices described above will be referred to in correspondence with each other.
Fig. 6 is a schematic structural diagram of an apparatus for transmitting data between devices according to an embodiment of the present application, as shown in fig. 6, specifically includes a determining module 601 configured to determine a second device for receiving first target data, a data transmitting module 602 configured to determine a target transmission mode according to network connection information of the first device and the second device, and transmit the first target data to the second device through the target transmission mode, where the first device is a device for performing authentication based on a first account, the second device is a device for performing authentication based on a second account, and the first account and the second account are associated accounts.
Optionally, the data transmission module 602 is specifically configured to, if the network connection information indicates that the second device and the first device are in the same network domain, establish a first communication connection with the second device, and transmit first target data to the second device through the first communication connection, where the first communication connection is a network connection in a network domain environment, and if not, the first device transmits the first target data to the second device through the second communication connection established with the server.
Optionally, the device further comprises a communication connection module 603, and the communication connection module 603 is used for establishing a second communication connection with the server after the authentication of the first account and the server is successful, wherein the second communication connection is used for data transmission with the server.
Optionally, the device further comprises an acquisition module 604, a determining module 601, and a determining module, wherein the acquisition module 604 is used for acquiring a device list logged in to the second account from the server, and the determining module is specifically used for determining a second device for receiving the first target data from the device list.
Optionally, the obtaining module 604 is further configured to obtain a first network parameter of a network domain where the second device is located, the communication connection module 603 is specifically configured to determine a network connection state with the second device in a network domain environment based on the first network parameter, and the communication connection module 603 is specifically further configured to establish a first communication connection with the second device if the first device and the second device have a network path in the network domain environment, where the first network parameter includes at least one of a network domain internet protocol IP address and a port number of the second device.
Optionally, the device further comprises a sending module 605, the sending module 605 is used for sending a first target information obtaining request to the server based on the first account, the first target information obtaining request is used for obtaining a first Token and a first encryption key corresponding to the first Token, and the first encryption key is used for encrypting first target data in a data transmission process.
Optionally, the sending module 605 is further configured to send the first Token to the second device, so that the second device obtains the first encryption key from the server based on the first Token and decrypts the encrypted first target data according to the first encryption key, and the data transmission module 602 is specifically configured to encrypt the first target data based on the first encryption key and send the encrypted first target data to the second device in a target transmission manner.
Optionally, the determining module 601 is further configured to determine whether the first Token is in the validity period based on the current time of the server, and the sending module 605 is further configured to send the first Token to the second device if the first Token is in the validity period.
Optionally, the sending module 605 is further configured to send, based on the first account, a second target information acquisition request to the server when the receiving module 606 receives the first Token invalidation message sent by the second device, where the second target information acquisition request is used to acquire a new Token and an encryption key.
Optionally, the sending module 605 is further configured to send a second network parameter of a network domain where the first device is located to the server, where the second network parameter is used by the second device to determine whether a network path exists with the first device in the network domain environment based on the second network parameter, and establish a third communication connection with the first device when the second device and the first device have the network path in the network domain environment, and the third communication connection is a network connection in the network domain environment.
Optionally, the receiving module 606 is further configured to receive a second Token sent by the second device through the third communication connection, and the obtaining module 604 is further configured to obtain, from the server, a second encryption key corresponding to the second Token based on the second Token, where the second encryption key is used to decrypt encrypted data transmitted by the second device to the first device through the third communication connection.
Optionally, the determining module 601 is further configured to determine validity of the second Token based on a current time of the server, the obtaining module 604 is specifically configured to obtain, based on the second Token, a second encryption key corresponding to the second Token from the server if the second Token is within the validity period, and otherwise, send a second Token invalidation message to the second device, where the second Token invalidation message is used to instruct the second device to re-obtain the Token from the server.
Optionally, the receiving module 606 is configured to receive a message queue sent by a server, and the receiving module 606 is further configured to generate a receiving sequence according to a sending sequence of a message in the message queue, and obtain, from the server, data to be transmitted corresponding to the message in the message queue according to the receiving sequence and a data identifier of the data to be transmitted in the server corresponding to the message in the message queue, where the message queue is generated by the server based on a sending time of data included in second target data sent by the second device when the first device is in an offline state.
Optionally, the device further comprises a file splitting module 607, a sending module 605, a receiving module 606 and a sending module 605, wherein the sending module 605 is further used for sending data information of the first target data to the server, the receiving module 606 is further used for receiving blocking information of the first target data sent by the server based on the data information, the blocking information comprises the number of data blocks corresponding to the first target data and numbers corresponding to each data block, the file splitting module 607 is used for splitting the first target data into at least one data block based on the blocking information, the number of the at least one data block is the same as the number of the data blocks, the obtaining module 604 is further used for obtaining the numbers corresponding to the unfinished target data blocks in the at least one data block when transmission interruption occurs in the process of transmitting the first target data to the server by the first device, and the sending module 605 is further used for re-sending the target data blocks to the server according to the numbers corresponding to the target data blocks after the first device and the server are newly connected in communication.
According to the device for transmitting data among the devices, which is provided by the application, the data can be transmitted among the devices, the faster data transmission can be selected from a transfer transmission mode or a near field communication setting mode of a server based on the network state information among the devices, the technical problems that the existing file transmission method, transmission device and transmission system are influenced by factors of hardware devices or the transmission speed is slower are solved, and the security in transmission can be effectively ensured based on the data encryption and decryption crime provided by the embodiment of the application. And when transmission interruption occurs and transmission is carried out again, continuous transmission can be carried out based on the number of the data block which is not transmitted and is corresponding to the first target data, repeated transmission of the data block which is transmitted and is completed is not needed, and the transmission efficiency is greatly improved.
Fig. 7 illustrates a physical schematic diagram of an electronic device, which may include a processor (processor) 710, a communication interface (Communications Interface) 720, a memory (memory) 730, and a communication bus 740, where the processor 710, the communication interface 720, and the memory 730 communicate with each other via the communication bus 740, as shown in fig. 7. The processor 710 may invoke logic instructions in the memory 730 to perform a method of transferring data between devices, the method comprising determining a second device for receiving first target data, determining a target transfer mode based on network connection information of the first device and the second device, and transferring the first target data to the second device via the target transfer mode, wherein the first device is a device for authentication based on a first account, the second device is a device for authentication based on a second account, and the first account and the second account are associated accounts.
Further, the logic instructions in the memory 630 may be implemented in the form of software functional units and stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method of the embodiments of the present application. The storage medium includes a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, an optical disk, or other various media capable of storing program codes.
In another aspect, the application also provides a computer program product comprising a computer program stored on a computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, are capable of performing the method of transferring data between devices provided by the methods described above, the method comprising determining a second device for receiving first target data, determining a target transfer mode according to network connection information of the first device and the second device, and transferring the first target data to the second device by the target transfer mode, wherein the first device is a device for performing authentication based on a first account, the second device is a device for performing authentication based on a second account, and the first account and the second account are associated accounts.
In yet another aspect, the present application further provides a computer readable storage medium having stored thereon a computer program, which when executed by a processor, implements a method for transmitting data between devices provided above, the method comprising determining a second device for receiving first target data, determining a target transmission manner according to network connection information of the first device and the second device, and transmitting the first target data to the second device through the target transmission manner, wherein the first device is a device for performing authentication based on a first account, the second device is a device for performing authentication based on a second account, and the first account and the second account are associated accounts.
The apparatus embodiments described above are merely illustrative, wherein elements illustrated as separate elements may or may not be physically separate, and elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on such understanding, the foregoing technical solutions may be embodied essentially or in part in the form of a software product, which may be stored in a computer-readable storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the various embodiments or methods of some parts of the embodiments.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present application, and not for limiting the same, and although the present application has been described in detail with reference to the above-mentioned embodiments, it should be understood by those skilled in the art that the technical solution described in the above-mentioned embodiments may be modified or some technical features may be equivalently replaced, and these modifications or substitutions do not make the essence of the corresponding technical solution deviate from the spirit and scope of the technical solution of the embodiments of the present application.