Disclosure of Invention
Therefore, it is necessary to provide a device interactive communication method, apparatus, storage medium, and computer device with faster, more convenient, and more efficient communication process, aiming at the problems of cumbersome communication process and low communication efficiency in the conventional technology.
A device interaction communication method, comprising:
constructing a communication data packet according to interactive communication content information of target equipment, wherein the communication data packet comprises a header, a body and a trailer;
sending the communication data packet to the target device according to information contained in the packet header in the communication data packet, wherein the communication data packet is used for indicating the target device to construct a response data packet according to the information contained in the packet header, the packet body and the packet tail in the communication data packet;
and receiving a response data packet sent by the target equipment according to the communication data packet.
A device interaction communication apparatus, comprising:
the first construction module is used for constructing a communication data packet according to interactive communication content information of target equipment, wherein the communication data packet comprises a packet head, a packet body and a packet tail;
the first sending module is used for sending the communication data packet to the target equipment according to information contained in the packet header of the communication data packet, wherein the communication data packet is used for carrying out interactive communication with the target equipment;
and the first receiving module is used for receiving a response data packet sent by the target equipment according to the communication data packet.
A device interaction communication method, comprising:
receiving a communication data packet which is sent by source equipment and constructed according to interactive communication content information, wherein the communication data packet comprises a packet head, a packet body and a packet tail;
constructing a response data packet according to information contained in the packet head, the packet body and the packet tail in the communication data packet;
and sending the response data packet to the source equipment according to the information contained in the packet header in the communication data packet.
A device interaction communication apparatus, comprising:
the second receiving module is used for receiving a communication data packet which is sent by source equipment and constructed according to interactive communication content information, wherein the communication data packet comprises a packet head, a packet body and a packet tail;
the second construction module is used for constructing a response data packet according to information contained in the packet head, the packet body and the packet tail in the communication data packet;
and the second sending module is used for sending the response data packet to the source equipment according to the information contained in the packet header in the communication data packet.
A storage medium having stored thereon a computer program which, when executed by a processor, implements the above-described device interactive communication method.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above device interactive communication method when executing the program.
In the device interactive communication method, the device, the storage medium and the computer device, when the devices are in interactive communication, a communication data packet is constructed according to interactive communication content information of target devices, wherein the communication data packet comprises a packet head, a packet body and a packet tail; sending the communication data packet to target equipment according to information contained in a packet header in the communication data packet, wherein the communication data packet is used for indicating the target equipment to construct a response data packet according to the information contained in the packet header, the packet body and the packet tail in the communication data packet; and receiving a response data packet sent by the target device according to the communication data packet. When the equipment is in interactive communication, receiving a communication data packet which is sent by source equipment and constructed according to interactive communication content information, wherein the communication data packet comprises a header, a body and a trailer; constructing a response data packet according to information contained in a packet head, a packet body and a packet tail in the communication data packet; and sending a response data packet constructed according to the communication data packet to the source equipment. The communication data packet used during communication of the network communication equipment is specifically defined, interactive communication can be directly carried out between the equipment, when a communication target is converted, connection does not need to be reestablished, and the time of interactive communication between the equipment is effectively shortened, so that the communication process between the network communication equipment is faster and more convenient, and the communication efficiency is improved.
Detailed Description
Fig. 1 is a flowchart illustrating a device interactive communication method according to an embodiment, as shown in fig. 1, the device interactive communication method includes the following steps:
step S110, constructing a communication data packet according to the interactive communication content information of the target device.
The communication data packet constructed according to the interactive communication content information includes a header, a body and a trailer. In this step, the source device serializes (serializes) the interactive communication content information with the target device by using an XML (eXtensible Markup Language) format. In this step, the interactive communication content information with the target device is serialized, that is, the interactive communication content information is converted into a transmittable form, and the serialized interactive communication content information respectively constitutes a header (Head), a Body (Body), and a trailer (Foot) of a communication data packet.
Step S120, sending the communication data packet to the target device according to the information contained in the packet header of the communication data packet.
The communication data packet is used for instructing the target device to construct a response data packet according to the information contained in the packet head, the packet body and the packet tail in the communication data packet. In this step, the source device sends the communication data packet to the target device according to the information contained in the packet header of the communication data packet, that is, the related information of the target device.
Step S130, receiving a response packet sent by the target device according to the communication packet.
In this step, after the target device receives the communication data packet constructed according to the interactive communication content information sent by the source device, the target device executes a corresponding operation behavior according to the interactive communication content included in the communication data packet, generates a response data packet corresponding to the communication data packet, and sends the generated response data packet to the source device. After receiving the response data packet sent by the target device, the source device completes one interactive communication with the target device on behalf of the source device.
The embodiment provides a device interactive communication method for source devices and target devices, which is characterized in that a communication data packet used in the communication of network communication devices is specifically defined, the devices can be directly interactively communicated, when a communication target is converted, connection does not need to be reestablished, and the time of interactive communication between the devices is effectively shortened, so that the communication process between the network communication devices is faster and more convenient, and the communication efficiency is improved.
In one embodiment, the interactive communication content information includes a source device IP address, a target device IP address, a behavior recognition identifier, a manufacturer identifier corresponding to the target device, a corresponding ID of the interactive communication content, a data size, a data type, a data content, and an interactive communication time; in this embodiment, step S110 includes steps 112 to 118.
And step 112, constructing a packet header according to the source device IP address, the target device IP address, the behavior identification mark, the manufacturer mark corresponding to the target device and the corresponding ID of the interactive communication content in the interactive communication content information.
In this step, the interactive communication content information includes an IP Address of the source device (Internet Protocol Address), an IP Address of the target device, a behavior identification identifier, a manufacturer identifier corresponding to the target device, and a corresponding ID of the interactive communication content. Wherein the source device IP address is an IP address of a device that constructs and transmits a communication data packet. The IP address of the target device is the IP address of the device for receiving the communication data packet which is sent by the source device and constructed according to the interactive communication content information. The content of the behavior identification mark is a decimal number, the behavior identification mark is used for identifying the operation behavior type of the communication data packet generated by the source equipment, such as access behavior, report behavior, heartbeat behavior and the like, the target equipment identifies the operation behavior of the communication data packet according to the behavior identification mark and executes a corresponding processing strategy according to different operation behaviors. The target device corresponds to the manufacturer identification, i.e. the identification of the user of the target network communication device. In this step, the source device performs serialization processing on the source device IP address, the target device IP address, the behavior identification identifier, the manufacturer identifier corresponding to the target device, and the corresponding ID of the interactive communication content in sequence by using an XML format, and the serialized source device IP address, target device IP address, behavior identification identifier, manufacturer identifier corresponding to the target device, and the corresponding ID of the interactive communication content constitute a packet header of the communication data packet.
Step 114, according to the data size, data type and data content of the interactive communication content in the interactive communication content information, a packet body is constructed.
In this step, the interactive communication content information includes a data size, a data type, and a data content of the interactive communication content. The data content is specific content that the source device needs to interactively communicate with the target device, such as a parameter value, an instruction action, or the like. In this step, the source device performs serialization processing on the data size, the data type and the data content of the interactive communication content in sequence by using an XML format, and the data size, the data type and the data content of the interactive communication content after the serialization processing form a body of the communication data packet.
And step 116, constructing a packet tail according to the interactive communication time in the interactive communication content information.
In this step, the interactive communication content information includes time of interactive communication between the source device and the target device, that is, time of initiating an interactive communication action by the source device. The source device carries out serialization processing on the interactive communication time by using an XML format, and the interactive communication time after the serialization processing forms the packet tail of the communication data packet.
And step 118, constructing a communication data packet according to the constructed packet head, the constructed packet body and the constructed packet tail.
In this step, after the packet header, the body and the tail are completed, the source device encapsulates the packet header, the body and the tail, and adds a packet header for identifying the interconnection type, thereby constructing a complete communication data packet.
According to the embodiment, the communication data is specifically defined, and the communication process is specifically defined, so that the equipment communication can support the random access and communication exchange among the equipment, and the expected effect of rapid and convenient combined networking of various manufacturers is achieved.
Fig. 2 is a flowchart illustrating a device interactive communication method in another embodiment, as shown in fig. 2, after step S130, the device interactive communication method further includes step S140 of determining whether interactive communication with the target device is successful according to a response packet sent by the target device. And if the interactive communication is successful, sending a heartbeat packet to the target equipment. Otherwise, returning to the step of constructing the communication data packet according to the interactive communication content information of the target equipment.
In this step, after receiving the response packet sent by the target device, the source device analyzes and processes the response packet to determine whether the interactive communication between the source device and the target device is successful. And if the interactive communication between the source equipment and the target equipment is successful, the source equipment sends a heartbeat packet to the target equipment. After the interactive communication is successful, the subsequent data transmission modes of the source device and the target device are the same as the format of the communication data packet, and only the subsequent behavior identification mark adopts the behavior represented by another self-defined number, such as the heartbeat behavior, to restrict the processing strategy of the data packet content.
If the interactive communication between the source device and the target device fails, the process returns to step S110, and the subsequent steps are repeated. When the number of cycles from step S110 to step S140 reaches a preset number, the source device abandons the interactive communication.
In this embodiment, when the source device sends the heartbeat packet to the target device, if the sending fails, the step returns to step S110, and the subsequent steps are repeated. The source device determines whether the heartbeat packet is successfully sent by determining the attribute of the return message, for example, if the heartbeat packet with the attribute of 1 is sent from the source device, the source device receives the response packet from the target device within a preset time threshold (e.g., 3 seconds), and if the attribute of the response packet analyzed by the source device is 1, the heartbeat is considered to be successful. If the source device does not receive a response from the target device within a preset time threshold, the source device judges that the heartbeat with the target device is lost (failure), and if the heartbeat fails, the source device tries to reconnect the target all the time without limit.
In this embodiment, after the interactive communication between the source device and the target device is successful, the source device continues to send the heartbeat packet to the target device, so that the network connection between the source device and the target device is maintained, and the subsequent interactive communication is more convenient and faster.
Fig. 3 is a schematic structural diagram of an apparatus interactive communication device in an embodiment, as shown in fig. 3, the apparatus interactive communication device includes: a first constructing module 110, a first sending module 120 and a first receiving module 130.
The first constructing module 110 is configured to construct a communication data packet according to the interactive communication content information with the target device, where the communication data packet includes a header, a body, and a trailer. The first building module 110 performs serialization processing on the interactive communication content information with the target device by using an XML format, that is, the interactive communication content information is converted into a transmittable form, and the serialized interactive communication content information respectively constitutes a header, a body and a trailer of a communication data packet.
The first sending module 120 is configured to send the communication data packet to the target device according to information included in a header of the communication data packet, where the communication data packet is used to instruct the target device to construct a response data packet according to information included in the header, a body, and a trailer of the communication data packet. The first sending module 120 sends the communication data packet to the target device according to the information contained in the packet header of the communication data packet, that is, the related information of the target device.
The first receiving module 130 is configured to receive a response packet sent by the target device according to the communication packet. After the target device receives a communication data packet which is sent by the source device and constructed according to the interactive communication content information, the target device executes a corresponding operation behavior according to the interactive communication content contained in the communication data packet, generates a response data packet corresponding to the communication data packet, and sends the generated response data packet to the source device. After receiving the response packet sent by the target device, the first receiving module 130 of the source device represents that the source device and the target device complete one interactive communication.
Fig. 4 is a schematic structural diagram of an apparatus for interactive communication in another embodiment, as shown in fig. 4, the apparatus further includes a first determining module 140. The first determining module 140 determines whether the interactive communication with the target device is successful according to the response packet sent by the target device. And if the interactive communication is successful, sending a heartbeat packet to the target equipment. Otherwise, returning to the step of constructing the communication data packet according to the interactive communication content information of the target equipment.
Fig. 5 is a flowchart illustrating a device interactive communication method according to another embodiment, and as shown in fig. 5, the device interactive communication method includes the following steps.
Step S210, receiving a communication data packet constructed according to the interactive communication content information sent by the source device. The communication data packet comprises a header, a body and a trailer. In this step, the target device receives a communication data packet including a packet header, a packet body, and a packet tail, which is sent by the source device.
Step S230, constructing a response data packet according to the information contained in the header, body and trailer of the communication data packet. In this step, after the target device obtains the communication data packet, the message header is decoded, the message identified as the interworking message is recognized, and the work of gradually decoding according to the format of the interworking message is performed. Decoding a packet head part in a communication data packet, respectively acquiring a source equipment IP address, a target equipment IP address, a behavior identification mark, a target equipment corresponding manufacturer mark and a corresponding ID of interactive communication content, and performing deserialization processing on the information. Then, the target device carries out deserialization processing on the body part of the communication data packet according to a predefined format, and acquires the data size, the data type and the data content of the interactive communication content. And finally, performing deserialization processing on the packet tail part to acquire the interactive communication time.
After the communication data packet is decoded, the target device empties the content contained in the packet body part according to the deserialization processing result obtained in the process and the specific communication format, responds the corresponding identification by the behavior identification of the packet head part, converses the IP address of the source device and the IP address of the target device, and changes the interactive communication time in the packet tail part into the time for responding the completion of the construction of the data packet. The response packet is usually sent immediately after the completion of the construction, so the interactive communication time in the packet tail part, i.e. the time when the completion of the construction of the response packet, can also be regarded as approximately equal to the time when the response packet is sent to the source device.
Step S240, sending the response packet to the source device according to the information contained in the packet header of the communication packet. In this step, after the target device constructs the response packet, the target device sends the response packet to the source device.
The embodiment provides an interactive communication method between target equipment and source equipment, which is characterized in that a communication data packet used in the communication of network communication equipment is specifically defined, the equipment can be directly interactively communicated, when a communication target is converted, connection does not need to be reestablished, and the time of interactive communication between the equipment is effectively shortened, so that the communication process between the network communication equipment is faster and more convenient, and the communication efficiency is improved.
Fig. 6 is a flowchart illustrating a device interactive communication method in another embodiment, as shown in fig. 6, after step S210 and before step S230, the device interactive communication method further includes step S220 of determining whether the received communication data packet is expired. And if the communication data packet is not expired, constructing a response data packet according to information contained in the packet head, the packet body and the packet tail of the communication data packet. And if the communication data packet is expired, discarding the communication data packet.
The embodiment can effectively ensure the timeliness of the direct interactive communication of the network equipment by adding the step of judging whether the communication data packet is expired or not, directly abandons the overtime communication data packet, can reduce unnecessary communication processes, and improves the communication efficiency.
In one embodiment, step S220 includes step 222 and step 224.
Step 222, acquiring the interactive communication time in the interactive communication content information according to the information contained in the packet tail in the communication data packet. In this step, the interactive communication time is obtained through the deserialization processing result of the packet tail part.
Step 224, determining whether the difference between the interactive communication time and the current system time is within a preset threshold range, and if so, determining that the received communication data packet is not expired. In this step, the criterion for judging whether the communication data packet is expired is: comparing the interactive communication time contained in the communication data packet with the current system time, and if the interactive communication time is within a preset threshold range (such as 180 seconds), determining that the communication data packet is an unexpired communication data packet and is a legal packet; if the preset threshold range is exceeded, the communication data packet is considered to be an expired communication data packet. For the expired communication data packet, the target device directly discards the packet information without performing subsequent processing.
In the step of judging whether the communication data packet is expired or not, the timeliness of the direct interactive communication of the network equipment can be further effectively ensured by comparing the interactive communication time contained in the packet tail of the communication data packet with the current system time, and the communication data packet which is overtime is directly discarded, so that unnecessary communication processes can be reduced, and the communication efficiency is improved.
Fig. 7 is a schematic structural diagram of an apparatus interactive communication device in another embodiment, as shown in fig. 7, the apparatus interactive communication device includes a second receiving module 210, a second constructing module 230, and a second sending module 240.
The second receiving module 210 is configured to receive a communication data packet sent by the source device and constructed according to the interactive communication content information. After the source device sends a communication data packet to the target device, the second receiving module 210 of the target device receives the communication data packet including a header, a body, and a trailer sent by the source device.
The second constructing module 230 is configured to construct the response data packet according to information included in the header, the body, and the trailer of the communication data packet. After receiving the communication data packet, the second building module 230 decodes the header, recognizes that the packet is an interworking packet, and performs a gradual decoding operation according to the format of the interworking packet. Decoding a packet head part in a communication data packet, respectively acquiring a source equipment IP address, a target equipment IP address, a behavior identification mark, a target equipment corresponding manufacturer mark and a corresponding ID of interactive communication content, and performing deserialization processing on the information. Then, the target device carries out deserialization processing on the body part of the communication data packet according to a predefined format, and acquires the data size, the data type and the data content of the interactive communication content. And finally, performing deserialization processing on the packet tail part to acquire the interactive communication time. After the communication data packet is decoded, the second constructing module 230 empties the content contained in the packet body part according to the deserialization result obtained in the above process and the specific communication format, responds the corresponding identifier by the behavior identification identifier of the packet head part, dialogs the IP address of the source device and the IP address of the target device, and changes the interactive communication time in the packet tail part into the time for responding to the completion of the data packet construction. The response packet is usually sent immediately after the completion of the construction, so the interactive communication time in the packet tail part, i.e. the time when the completion of the construction of the response packet, can also be regarded as approximately equal to the time when the response packet is sent to the source device.
The second sending module 240 is configured to send the response packet to the source device according to information included in the packet header of the communication packet. After the second constructing module 230 constructs the response packet, the second sending module 240 sends the response packet to the source device.
Fig. 8 is a schematic structural diagram of an apparatus interactive communication device in another embodiment, as shown in fig. 8, the apparatus interactive communication device further includes a second determining module 220. The second determination module 220 determines whether the received communication data packet is expired. And if the communication data packet is not expired, constructing a response data packet according to information contained in the packet head, the packet body and the packet tail of the communication data packet. And if the communication data packet is expired, discarding the communication data packet.
In one embodiment, a computer-readable storage medium is further provided, on which a computer program is stored, wherein the program, when executed by a processor, implements any one of the device interactive communication methods in the above embodiments. The storage medium may be an optical disc, a read-only memory, a random access memory, or the like. In the process of implementing the embodiment of the method for the interactive communication of the devices, the communication data packet used in the communication of the network communication devices is specifically defined, the devices can directly perform the interactive communication, when the communication target is converted, connection does not need to be reestablished, the time of the interactive communication between the devices is effectively shortened, the communication process between the network communication devices is faster and more convenient, and the communication efficiency is improved.
In one embodiment, a computer device is further provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the program to implement the device interactive communication method in any one of the above embodiments. When the processor of the computer equipment executes the program, in the process of realizing the embodiment of the interactive communication method of the equipment, the interactive communication can be directly carried out between the equipment by specifically defining the communication data packet used in the communication of the network communication equipment, when the communication target is converted, the connection does not need to be reestablished, the time of the interactive communication between the equipment is effectively shortened, the communication process between the network communication equipment is quicker and more convenient, and the communication efficiency is improved.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.