CN114697258A - Data communication method, device, electronic equipment and storage medium - Google Patents

Data communication method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114697258A
CN114697258A CN202210375351.5A CN202210375351A CN114697258A CN 114697258 A CN114697258 A CN 114697258A CN 202210375351 A CN202210375351 A CN 202210375351A CN 114697258 A CN114697258 A CN 114697258A
Authority
CN
China
Prior art keywords
data
data communication
equipment
packet
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210375351.5A
Other languages
Chinese (zh)
Other versions
CN114697258B (en
Inventor
谢知恒
钟晓锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202210375351.5A priority Critical patent/CN114697258B/en
Publication of CN114697258A publication Critical patent/CN114697258A/en
Application granted granted Critical
Publication of CN114697258B publication Critical patent/CN114697258B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/16Multipoint routing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2212/00Encapsulation of packets

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention discloses a data communication method, a data communication device, electronic equipment and a storage medium; in the invention, a first device sends a query data packet to a multicast address corresponding to a preset multicast group, wherein the query data packet carries a network address of the first device; the second equipment acquires an inquiry data packet based on the multicast address, and the first equipment and the second equipment belong to a preset multicast group; the second equipment determines the data communication type and acquires target data, and the target data are packaged by adopting a preset data format; the second equipment sends the target data to the first equipment based on the network address and the data communication type; the first device receives target data. In the invention, the first device can send the inquiry data packet carrying the network address of the first device to the multicast address, and the second device can acquire the inquiry data packet based on the multicast address and then can perform data communication with the first device based on the network address. Therefore, the data communication efficiency can be improved.

Description

Data communication method, device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of communication network technologies, and in particular, to a data communication method, apparatus, electronic device, and storage medium.
Background
With the rapid development of science and technology, people need to rely on various electronic devices in daily life. In some complex scenarios, one or more central electronic devices (e.g., servers) may need to organize and coordinate multiple other electronic devices to implement a large and complex system, so as to perform specific functions to solve problems in people's lives. A good way of data communication between electronic devices is crucial for the efficient operation of the system.
However, the efficiency of data communication between electronic devices is low.
Disclosure of Invention
The invention provides a data communication method, a data communication device, electronic equipment and a storage medium, which can improve the efficiency of data communication.
The invention provides a data communication method, which comprises the following steps:
the first equipment sends a query data packet to a multicast address corresponding to a preset multicast group, wherein the query data packet carries the network address of the first equipment;
the second equipment acquires an inquiry data packet based on the multicast address, and the first equipment and the second equipment belong to a preset multicast group;
the second equipment determines the data communication type and acquires target data, and the target data is packaged by adopting a preset data format;
the second equipment sends the target data to the first equipment based on the network address and the data communication type;
the first device receives target data.
The invention provides a data communication method, which is suitable for second equipment and comprises the following steps:
acquiring an inquiry data packet based on a multicast address corresponding to a preset multicast group, wherein the inquiry data packet carries a network address of first equipment, and the first equipment and second equipment belong to the preset multicast group;
determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format;
the target data is transmitted to the first device based on the network address and the data communication type.
The present invention also provides a data communication apparatus comprising:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring an inquiry data packet based on a multicast address corresponding to a preset multicast group, the inquiry data packet carries a network address of first equipment, and the first equipment and second equipment belong to the preset multicast group;
the determining unit is used for determining the data communication type and acquiring target data, and the target data is packaged by adopting a preset data format;
and the sending unit is used for sending the target data to the first equipment based on the network address and the data communication type.
In some embodiments, the data communication type is a first type, and the sending unit is specifically configured to:
sending a connection establishment data packet to the first device based on the network address, the connection establishment data packet being used to request establishment of a communication connection with the first device;
when the communication connection with the first equipment is successfully established, serializing the target data into a character string, and determining the length of the character string;
the character string length and the character string are transmitted to the first device in a binary stream based on the communication connection established with the first device.
In some embodiments, the sending unit is specifically configured to:
receiving an acknowledgement packet from the first device, the acknowledgement packet indicating that the first device acknowledges the establishment of the communication connection with the second device;
and after the reply confirmation data packet is sent to the first equipment, the communication connection with the first equipment is successfully established, and the reply confirmation data packet represents that the second equipment receives the confirmation data packet of the first equipment.
In some embodiments, the data communication type is a second type, and the sending unit is specifically configured to:
serializing the target data into a character string;
generating a target data packet, wherein the load of the target data packet comprises a character string;
and sending the target data packet to the first device based on the network address.
In some embodiments, the determining unit is specifically configured to:
monitoring the network state of a target communication network, wherein the target communication network is a communication network in which a first device and a second device are positioned;
based on the network status, a data communication type is determined.
In some embodiments, the query packet further carries a communication type parameter, and the determining unit is specifically configured to:
based on the communication type parameter, a data communication type is determined.
The invention also provides electronic equipment, which comprises a memory and a processor, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to perform the steps of any of the data communication methods provided by the present invention.
The present invention also provides a computer readable storage medium storing a plurality of instructions adapted to be loaded by a processor to perform the steps of any of the data communication methods provided by the present invention.
In the invention, a first device sends a query data packet to a multicast address corresponding to a preset multicast group, wherein the query data packet carries a network address of the first device; the second equipment acquires an inquiry data packet based on the multicast address, and the first equipment and the second equipment belong to a preset multicast group; the second equipment determines the data communication type and acquires target data, and the target data are packaged by adopting a preset data format; the second equipment sends the target data to the first equipment based on the network address and the data communication type; the first device receives target data. In the invention, the first device can send the inquiry data packet carrying the network address of the first device to the multicast address, and the second device can acquire the inquiry data packet based on the multicast address and then can perform data communication with the first device based on the network address. Therefore, the data communication efficiency can be improved.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flow chart illustrating a data communication method provided by the present invention;
FIG. 2 is a schematic diagram of a raspberry pi scenario with the data communication method provided by the present invention;
FIG. 3 is a schematic diagram of a data communication device according to the present invention;
fig. 4 is a schematic structural diagram of an electronic device provided in the present invention.
Detailed Description
The technical solutions in the present invention will be described clearly and completely with reference to the accompanying drawings, and it is obvious that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention provides a data communication method, a data communication device, an electronic device and a storage medium.
The data communication apparatus may be specifically integrated in an electronic device, and the electronic device may be a first device and a second device. The first device may be a server, and the server may be a single server or a server cluster composed of a plurality of servers; the second device can be raspberry group, mobile phone, tablet computer, intelligent bluetooth device, notebook computer, desktop computer, vehicle-mounted device and other devices.
In some embodiments, the data communication apparatus may also be integrated into a plurality of electronic devices, for example, the data communication apparatus may be integrated into one or more first devices and one or more second devices, and the first device and the second device jointly implement the data communication method of the present invention.
For example, the data communication method of the present invention may be collectively implemented by a plurality of first devices and one second device. The first device and the second device can be connected in communication through a router, and a communication network formed by the first device, the second device, the router and the like can be called a target communication network. In some embodiments, the router may support a Multicast Routing Protocol, and the Multicast Routing Protocol may be any one of Cisco Group Management Protocol (CGMP), Interior Gateway Routing Protocol (IGMP), Protocol Independent Multicast (PIM), and the like. In some embodiments, a third-party device may access the target communication network through a router, and the first device, the second device, and the third-party device collectively implement the data communication method of the present invention.
In some embodiments, a first device sends an inquiry data packet to a multicast address corresponding to a preset multicast group, where the inquiry data packet carries a network address of the first device; the second equipment acquires an inquiry data packet based on the multicast address, and the first equipment and the second equipment belong to a preset multicast group; the second equipment determines the data communication type and acquires target data, and the target data are packaged by adopting a preset data format; the second equipment sends the target data to the first equipment based on the network address and the data communication type; the first device receives target data.
In this embodiment, the first device may send an inquiry packet carrying its own network address to the multicast address, and the second device may obtain the inquiry packet based on the multicast address, and then may perform data communication with the first device based on the network address. Therefore, the data communication efficiency can be improved.
The following are detailed below. The numbers in the following examples are not intended to limit the order of preference of the examples.
In this embodiment, a data communication method is provided, and as shown in fig. 1, a specific flow of the data communication method may be as follows:
110. the first device sends a query data packet to a multicast address corresponding to a preset multicast group, and the query data packet carries the network address of the first device.
The preset multicast group may be a multicast group to which the first device and the second device belong. In some embodiments, a first device (sender) in a predetermined multicast group may perform data communication with a plurality of second devices (receivers), and the first device may send only one data packet, and the second devices belonging to the predetermined multicast group may all receive copies of the data packet. In some embodiments, the second device may also be a sender, and the first device and the other second devices may also be receivers.
In some embodiments, before sending the query packet to the multicast address corresponding to the preset multicast group, any one of the first device and the second device may apply for the preset multicast group, where the preset multicast group is maintained in the multicast router, and the other devices may apply for joining the multicast group.
The multicast address may be an Internet Protocol (IP) address corresponding to a preset multicast group; for example, one of D-type addresses of IPv4/6(Internet Protocol Version4/6) may be selected as the multicast address, and one of D-type addresses of 224.0.0.0 to 239.255.255.255 may be selected as the multicast address. In some embodiments, a port corresponding to the multicast address may also be specified.
The network address of the first device may refer to the IP address and port corresponding to the first device.
The query packet may be a packet generated based on a User Datagram Protocol (UDP). The user datagram protocol is a connectionless transport layer protocol. In some embodiments, the query packet may include, but is not limited to, a dummy header, a header, and a data portion. The pseudo header has 12 bytes, and may include, but is not limited to, fields such as a source address, a destination address, and a reserved field, where the source address may include an IP address of the first device, and the destination address may include a multicast address. The header may include, but is not limited to, fields such as source port, destination port, length, and check value; the source port field may occupy the first 16 bits of the header of the packet, and may include a port of the first device, and the second device may use a value of the field as a destination address for sending a response; the destination port may include a port corresponding to the multicast address, and may occupy 16 bits of the header; the length field can occupy 16 bits of the message header, represents the length of the query data packet, and comprises the data length of the message header and the data length of the load part; and (3) checking the value: this field occupies 16 bits and can check whether the data is corrupted during transmission. In some embodiments, the network address of the first device may also be included in the data portion, for example, the network address of the first device may be encapsulated as a json object, and the json object may be placed in the data portion after being serialized.
120. And the second equipment acquires the query data packet based on the multicast address, and the first equipment and the second equipment belong to a preset multicast group.
The second device may listen to the multicast address, and when the router corresponding to the multicast address receives the query packet, the router may forward the query packet to all the second devices (listeners) listening to the multicast address. Accordingly, the second device may obtain the query packet. Therefore, the method for acquiring the network address between the electronic devices is more flexible, can be suitable for a large and complex system, is easy to maintain, and is convenient for external third-party devices to access a target communication network and the like.
In some embodiments, the manner of maintaining the listener corresponding to the multicast address may include, but is not limited to:
the router sends a query (General Queries) message as an inquirer to all second devices connected to it. After receiving the query message, the second device responds to the query message, and replies a message containing the multicast address state record of the preset multicast group to the router, wherein the message can enable the router to determine that the second device is monitoring the multicast address or monitoring the query data packet from the first device.
When the second device leaves the preset multicast group, the second device may send a message of completion of the multicast listener to the router, where the message includes a State Change record (State Change Records). After receiving the message completed by the multicast listener, the router sends an inquiry message of the multicast address to a communication link connected with the router, and inquires whether other second equipment joins the preset multicast group.
If the multicast listener reporting message containing the state change record sent by the second device is still not received after the relevant timer of the preset multicast group maintained in the router is overtime, the router sends the query message of the multicast address to all the second devices so as to confirm whether the preset multicast group has any listener.
130. And the second equipment determines the data communication type and acquires target data, and the target data is packaged by adopting a preset data format.
The data communication type refers to a communication type for performing data communication between a first device and a second device, where the data communication type may include, but is not limited to, a first type and a second type, for example, the first type may be a communication mode requiring communication connection establishment, such as a data communication mode based on a Transmission Control Protocol (TCP), and the second type may be a communication mode requiring no communication connection establishment, such as a data communication mode based on a UDP; the first device and the second device may communicate wirelessly or by wire (e.g., optical fiber, twisted pair, coaxial cable, etc.).
The target data may be any data that needs to be sent to the first device. The predetermined data format may be a data format capable of normalizing the target data, such as a json object, for example, the target data may be represented by { "ID": 224.0.0.0"," alexa ": 10000", "site": null }.
In some embodiments, the first device monitors a network status of a target communication network, the target communication network being a communication network in which the first device and the second device are located; based on the network status, a data communication type is determined. For example, when the network state is stable, the data communication type is determined to be a UDP-based data communication mode, and data communication between the first device and the second device is implemented. And when the network state is unstable, determining the data communication type as a data communication mode based on TCP, and realizing data communication between the first equipment and the second equipment. When the network state is stable, the data communication cost between the first device and the second device can be reduced, and network resources are saved.
In some embodiments, the query packet also carries a communication type parameter, and the second device may determine the data communication type based on the communication type parameter. For example, when a third-party device accesses the target communication network, the query packet may carry a communication type parameter, where the communication type parameter may be used to indicate that the third-party device accesses the target communication network, and the second device may determine that the data communication type is the second type based on the communication type parameter. In some embodiments, the third party device may also perform data communication with the first device or the second device based on the second type of data communication type, which may reduce the cost of accessing the target communication network by the third party device.
140. The second device transmits the target data to the first device based on the network address and the data communication type. Accordingly, the first device receives the target data.
In some embodiments, the data communication type is a first type, and the sending of the target data to the first device based on the network address and the data communication type may include, but is not limited to:
i. the second device sends a connection establishment data packet to the first device based on the network address, wherein the connection establishment data packet is used for requesting to establish communication connection with the first device; accordingly, the first device receives the connection establishment packet, and can establish a communication connection with the second device. In some embodiments, to establish a reliable communication connection, the first device may send an acknowledgement packet to the second device after receiving the connection establishment packet; the second device receives an acknowledgement data packet from the first device, wherein the acknowledgement data packet indicates that the first device confirms that the communication connection is established with the second device; and the second equipment sends a reply confirmation data packet to the first equipment, and correspondingly, when the first equipment receives the reply confirmation data packet, the communication connection between the second equipment and the first equipment is successfully established, reliable data communication can be carried out, and the reply confirmation data packet represents that the second equipment receives the confirmation data packet of the first equipment.
ii. And after the second device successfully establishes communication connection with the first device, serializing the target data into a character string, and determining the character string length of the character string. Where serialization is the process of converting target data (e.g., json objects) into binary strings (character strings).
And iii, the second device transmits the character string length and the character string to the first device in a binary stream based on the communication connection established with the first device. For example, the second device writes the length of the character string into a binary stream of the TCP communication connection, and then writes the character string corresponding to the target data into the binary stream; correspondingly, when the first device receives the data, reading the length of the character string from the binary stream, reading the corresponding byte according to the length of the character string, and performing deserialization on the byte to obtain target data; deserialization is the process of converting the string corresponding to the target data into a json object.
In some embodiments, after data communication between the first device and the second device is completed, the communication connection between the first device and the second device may be disconnected. Before disconnection, the second device and the first device are both in an ESTABLISHED connection (ESTABLISHED) state, and both devices can actively disconnect the communication connection, which is exemplified by the second device actively disconnecting the communication connection.
The second device wants to disconnect the communication connection, sends a connection release (FIN) message to the first device, wherein a serial number can be designated in the FIN message, and then the second device enters a first connection waiting for closing (FIN _ WAIT _1) state to WAIT for the confirmation of the first device.
After receiving the connection release message from the second device, the first device sends an Acknowledgement (ACK) message to the second device. The first device enters a WAIT for CLOSE (CLOSE _ WAIT) state, in which the communication connection is in a semi-closed state, and may also send data to the second device, but may not receive data from the second device. And after receiving the acknowledgement message of the first equipment, the second equipment enters a second connection closing waiting (FIN _ WAIT _2) state.
The first device also wants to disconnect the communication connection, sends a connection release message to the second device, and the first device enters a last acknowledgement (LASK _ ACK) state to wait for the acknowledgement of the second device.
After receiving the connection release message from the first device, the second device may send an acknowledgement message (ACK) to the first device, and the second device enters a TIME _ WAIT state. After the first device receives the reply message, the first device enters a CLOSE (CLOSE) state, and the communication connection to the first device is closed.
The second device enters a TIME _ WAIT state, and after waiting for a preset TIME interval, the second device enters a closed state, and the preset TIME interval can be set in a user-defined manner according to the actual application condition.
In some embodiments, the data communication type is a second type, and the sending of the target data to the first device based on the network address and the data communication type may include, but is not limited to:
the second device serializes the target data into a character string; generating a target data packet, wherein the load of the target data packet comprises a character string; sending a target data packet to the first device based on the network address; accordingly, the first device receives the destination data packet. For example, the second device may serialize the json object into a character string, and fill the character string into a payload of a UDP packet to obtain a target packet, and send the target packet to the first device; when the first device receives the target data packet, deserializing the load of the target data packet into a json object by using the load as a character string to obtain target data.
It should be noted that the first device may also send data to the second device, and the data communication method of the present invention is described in this embodiment by taking only the example that the second device sends the target data to the first device. Similarly, data communication can be performed between the first device and the first device or/and between the second device and the second device or/and between the second device and the third-party device or/and between the first device and the third-party device by using the data communication method of the present invention, which is not described in detail in this embodiment.
As can be seen from the above, in this embodiment, a preset multicast group may be applied, and the first device may send an inquiry packet carrying its own network address to a multicast address corresponding to the preset multicast group; the second device can monitor the multicast address and obtain the query data packet sent by the first device, namely the second device can obtain the network address of the first device, the mode of obtaining the network address between the electronic devices is more flexible, the method is applicable to large and complex systems, and the method is easy to maintain and is convenient for external third-party devices to access a target communication network and the like. The second device may then determine the data communication type based on the network status of the target communication network and/or whether a third party device has joined the target communication network; when the network state is stable or a third-party device joins the target communication network, data communication can be carried out in a communication mode without establishing communication connection; when the network state is unstable, data communication can be carried out by adopting a mode of establishing communication connection; therefore, the data communication mode is selected according to the network state or whether the third-party equipment is accessed, so that the data communication mode is more reasonable, and the efficiency of data communication between subsequent electronic equipment can be improved. Finally, after the data communication mode is determined, data communication can be performed, and in this embodiment, the target data is packaged in a preset data format, so that the target data can be transmitted between the electronic devices more conveniently. Therefore, the present embodiment can improve the efficiency of data communication.
The data communication scheme provided by the invention can be applied to scenes that data communication is carried out after connection needs to be established among various electronic devices. For example, the first device is a server, and the second device is a raspberry pi; referring to fig. 2, it is a schematic diagram that a data communication method provided in this embodiment is applied in a raspberry pi scenario, where the data communication method includes a plurality of raspberry pis and a server, and the number in the diagram is merely an example and does not limit the present invention. The server and the raspberry pie can be in communication connection through the router; in some embodiments, the router (multicast router) may support multicast routing protocols, which may be the PIM protocol and the IGMP protocol. In some embodiments, the raspberry group may be a microcomputer motherboard based on an ARM processor (Advanced RISC Machine), and may use an SD/MicroSD card as a memory hard disk, and there may be 1/2/4 USB interfaces around the motherboard, and may also have a 10/100 ethernet Interface, which may connect a keyboard, a mouse, and a network cable, and may have a television output Interface and a High Definition Multimedia Interface (HDMI) for video analog signals, and as long as the display screen and the keyboard are connected, it may perform many functions such as table processing, word processing, game playing, and High Definition video playing.
The method described in the above embodiments is further described in detail below.
The data communication method comprises the following specific processes:
210. and the server sends a query data packet to a multicast address corresponding to the preset multicast group, and the query data packet carries the network address of the server.
For example, the server may apply for a preset multicast group, and assume that the multicast address corresponding to the preset multicast group is 224.1.1.1, and is maintained by the multicast router. The server sends a query packet to 224.1.1.1, the query packet carrying the IP address and port of the server.
220. And the raspberry group obtains the query data packet based on the multicast address, and the server and the raspberry group belong to a preset multicast group.
The raspberry pi (listener) can listen 224.1.1.1, and when the multicast router receives the query packet, the multicast router can forward the query packet to all listeners listening to the multicast address. Therefore, the raspberry pi can obtain the query data packet to obtain the IP address and the port of the server.
230. And determining the data communication type by the raspberry group, and acquiring target data, wherein the target data is packaged by adopting a preset data format.
The method comprises the following steps that a server monitors the network state of a target communication network, wherein the target communication network is a communication network where the server and a raspberry are located; and when the network state is stable, determining that the data communication type is a UDP-based data communication mode, and realizing the data communication between the server and the raspberry group. And when the network state is unstable, determining the data communication type as a data communication mode based on the TCP.
And encapsulating the target data by adopting a json object.
240. And the raspberry party sends the target data to the server based on the network address and the data communication type. Accordingly, the server receives the target data.
When the data communication type is a data communication mode based on TCP, the raspberry firstly writes the length of the character string into a binary stream of TCP communication connection, and then writes the character string corresponding to the target data into the binary stream; correspondingly, when the server receives the data, firstly reading the length of the character string from the binary stream, then reading the corresponding byte according to the length of the character string, and deserializing the byte to obtain target data; deserialization is the process of converting the string corresponding to the target data into a json object.
When the data communication type is a UDP-based data communication mode, the raspberry group can serialize the json object into a character string and fill the character string into the load of the UDP data packet to obtain a target data packet, and the raspberry group sends the target data packet to the server; and when the server receives the target data packet, deserializing the load of the target data packet into a json object by taking the load as a character string to obtain target data.
As can be seen from the above, in this embodiment, a preset multicast group may be applied by a server or a raspberry group, and the server may send an inquiry data packet carrying its own network address to a multicast address corresponding to the preset multicast group; the raspberry group can monitor the multicast address, the query data packet sent by the server is obtained, namely the network address of the server can be obtained by the raspberry group, the mode of obtaining the network address between the raspberry group and the server is more flexible, the method is applicable to large and complex systems, and the method is easy to maintain and is convenient for external third-party equipment to access a target communication network and the like. The raspberry pi may then determine the data communication type based on the network status of the target communication network and/or whether a third party device joins the target communication network; when the network state is stable or a third-party device joins the target communication network, data communication can be carried out in a communication mode based on a UDP protocol; when the network state is unstable, data communication can be carried out by adopting a communication mode based on a TCP (transmission control protocol); therefore, the data communication mode is selected according to the network state or whether the third-party equipment is accessed, so that the data communication mode is more reasonable, and the efficiency of data communication between the subsequent raspberry group and the server can be improved. Finally, after the data communication mode is determined, data communication can be performed, in this embodiment, the target data is encapsulated by adopting a json object, and the target data is more conveniently transmitted between the raspberry pi and the server. Therefore, the present embodiment can improve the efficiency of data communication.
In order to better implement the above method, the present invention further provides a data communication apparatus, for example, in this embodiment, the method of the present invention will be described in detail by taking the data communication apparatus as an example, which is specifically integrated in the second device.
For example, as shown in fig. 3, the data communication apparatus may include an acquisition unit 301, a determination unit 302, and a transmission unit 303, as follows:
an obtaining unit 301, configured to obtain an inquiry packet based on a multicast address corresponding to a preset multicast group, where the inquiry packet carries a network address of a first device, and the first device and a second device belong to the preset multicast group;
a determining unit 302, configured to determine a data communication type and obtain target data, where the target data is encapsulated in a preset data format;
a sending unit 303, configured to send the target data to the first device based on the network address and the data communication type.
In some embodiments, the data communication type is a first type, and the sending unit 303 is specifically configured to:
sending a connection establishment data packet to the first device based on the network address, the connection establishment data packet being used to request establishment of a communication connection with the first device;
when the communication connection with the first equipment is successfully established, serializing the target data into a character string, and determining the length of the character string;
the character string length and the character string are transmitted to the first device in a binary stream based on the communication connection established with the first device.
In some embodiments, the sending unit 303 is specifically configured to:
receiving an acknowledgement packet from the first device, the acknowledgement packet indicating that the first device acknowledges the establishment of the communication connection with the second device;
and after the reply confirmation data packet is sent to the first equipment, the communication connection with the first equipment is successfully established, and the reply confirmation data packet represents that the second equipment receives the confirmation data packet of the first equipment.
In some embodiments, the data communication type is a second type, and the sending unit 303 is specifically configured to:
serializing the target data into a character string;
generating a target data packet, wherein the load of the target data packet comprises a character string;
and sending the target data packet to the first device based on the network address.
In some embodiments, the determining unit 302 is specifically configured to:
monitoring the network state of a target communication network, wherein the target communication network is a communication network in which a first device and a second device are positioned;
based on the network status, a data communication type is determined.
In some embodiments, the query packet further carries a communication type parameter, and the determining unit 302 is specifically configured to:
based on the communication type parameter, a data communication type is determined.
In a specific implementation, the above units may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and the specific implementation of the above units may refer to the foregoing method embodiments, which are not described herein again.
As can be seen from the above, the data communication apparatus of this embodiment may obtain the query packet based on the multicast address, where the first device and the second device belong to a preset multicast group; determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format; transmitting the target data to the first device based on the network address and the data communication type; accordingly, the first device receives the target data. In the invention, the query data packet can be obtained based on the multicast address, the query data packet is a data packet which is sent to the multicast address by the first device and carries the network address of the first device, and then data communication can be carried out with the first device based on the network address. Therefore, the data communication efficiency can be improved.
Accordingly, an electronic device is further provided in the embodiments of the present application, for example, in the embodiments, the electronic device is taken as a second device for detailed description, as shown in fig. 4, fig. 4 is a schematic structural diagram of the electronic device provided in the embodiments of the present application, and the electronic device 400 includes a processor 401 having one or more processing cores, a memory 402 having one or more computer-readable storage media, and a computer program stored on the memory 402 and capable of running on the processor. The processor 401 is electrically connected to the memory 402. Those skilled in the art will appreciate that the electronic device configurations shown in the figures do not constitute limitations of the electronic device, and may include more or fewer components than shown, or some components in combination, or a different arrangement of components.
The processor 401 is a control center of the electronic device 400, connects various parts of the whole electronic device 400 by using various interfaces and lines, performs various functions of the electronic device 400 and processes data by running or loading software programs and/or modules stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the electronic device 400.
In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to processes of one or more application programs into the memory 402 according to the following steps, and the processor 401 runs the application programs stored in the memory 402, so as to implement various functions:
acquiring an inquiry data packet based on a multicast address corresponding to a preset multicast group, wherein the inquiry data packet carries a network address of first equipment, and the first equipment and second equipment belong to the preset multicast group;
determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format;
the target data is transmitted to the first device based on the network address and the data communication type.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
Optionally, as shown in fig. 4, the electronic device 400 further includes: a touch display 403, a radio frequency circuit 404, an audio circuit 405, an input unit 406, and a power supply 407. The processor 401 is electrically connected to the touch display screen 403, the radio frequency circuit 404, the audio circuit 405, the input unit 406, and the power source 407. Those skilled in the art will appreciate that the electronic device configuration shown in fig. 4 does not constitute a limitation of the electronic device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
The touch display screen 403 may be used for displaying a graphical user interface and receiving operation instructions generated by a user acting on the graphical user interface. The touch display screen 403 may include a display panel and a touch panel. The display panel may be used, among other things, to display information entered by or provided to a user and various graphical user interfaces of the electronic device, which may be made up of graphics, text, icons, video, and any combination thereof. Alternatively, the Display panel may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like. The touch panel may be used to collect touch operations of a user on or near the touch panel (for example, operations of the user on or near the touch panel using any suitable object or accessory such as a finger, a stylus pen, and the like), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Alternatively, the touch panel may include two parts, a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 401, and can receive and execute commands sent by the processor 401. The touch panel may overlay the display panel and, when the touch panel detects a touch operation thereon or nearby, transmit the touch operation to the processor 401 to determine the type of the touch event, and then the processor 401 provides a corresponding visual output on the display panel according to the type of the touch event. In the embodiment of the present application, the touch panel and the display panel may be integrated into the touch display screen 403 to realize input and output functions. However, in some embodiments, the touch panel and the touch panel can be implemented as two separate components to perform the input and output functions. That is, the touch display screen 403 may also be used as a part of the input unit 406 to implement an input function.
In the embodiment of the present application, an application program is executed by the processor 401 to generate a graphical user interface on the touch display screen 403. The touch display screen 403 is used for presenting a graphical user interface and receiving an operation instruction generated by a user acting on the graphical user interface.
The rf circuit 404 may be used for transceiving rf signals to establish wireless communication with a network device or other electronic devices via wireless communication, and for transceiving signals with the network device or other electronic devices.
The audio circuit 405 may be used to provide an audio interface between the user and the electronic device through a speaker, microphone. The audio circuit 405 may transmit the electrical signal converted from the received audio data to a speaker, and convert the electrical signal into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 405 and converted into audio data, which is then processed by the audio data output processor 401 and then transmitted to, for example, another electronic device via the rf circuit 404, or the audio data is output to the memory 402 for further processing. The audio circuit 405 may also include an earbud jack to provide communication of a peripheral headset with the electronic device.
The input unit 406 may be used to receive input numbers, character information, or user characteristic information (e.g., fingerprint, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
The power supply 407 is used to power the various components of the electronic device 400. Optionally, the power source 407 may be logically connected to the processor 401 through a power management system, so as to implement functions of managing charging, discharging, power consumption management, and the like through the power management system. The power supply 407 may also include one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, or any other component.
Although not shown in fig. 4, the electronic device 400 may further include a camera, a sensor, a wireless fidelity module, a bluetooth module, etc., which are not described in detail herein.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to the related descriptions of other embodiments.
As can be seen from the above, the electronic device provided in this embodiment may obtain the query packet based on the multicast address, where the first device and the second device belong to a preset multicast group; determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format; transmitting the target data to the first device based on the network address and the data communication type; accordingly, the first device receives the target data. In the invention, the query data packet can be acquired based on the multicast address, the query data packet is a data packet which is sent to the multicast address by the first device and carries the network address of the first device, and then data communication can be carried out with the first device based on the network address. Therefore, the data communication efficiency can be improved.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, the present application provides a computer-readable storage medium, in which a plurality of computer programs are stored, and the computer programs can be loaded by a processor to execute the steps in any data communication method provided by the present application. For example, the computer program may perform the steps of:
acquiring an inquiry data packet based on a multicast address corresponding to a preset multicast group, wherein the inquiry data packet carries a network address of first equipment, and the first equipment and second equipment belong to the preset multicast group;
determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format;
the target data is transmitted to the first device based on the network address and the data communication type.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
Wherein the storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the computer program stored in the storage medium can execute the steps in any data communication method provided in the embodiments of the present application, the beneficial effects that can be achieved by any data communication method provided in the embodiments of the present application can be achieved, and detailed descriptions are omitted here for the foregoing embodiments.
The data communication method, the data communication device, the data communication storage medium, and the electronic device provided in the embodiments of the present application are described in detail above, and a specific example is applied to illustrate the principles and embodiments of the present application, and the description of the embodiments is only used to help understand the method and the core concept of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method of data communication, comprising:
a first device sends a query data packet to a multicast address corresponding to a preset multicast group, wherein the query data packet carries a network address of the first device;
the second equipment acquires an inquiry data packet based on the multicast address, and the first equipment and the second equipment belong to the preset multicast group;
the second equipment determines the data communication type and acquires target data, and the target data are packaged by adopting a preset data format;
the second device sends the target data to the first device based on the network address and the data communication type;
the first device receives the target data.
2. A data communication method, adapted to a second device, comprising:
acquiring an inquiry data packet based on a multicast address corresponding to a preset multicast group, wherein the inquiry data packet carries a network address of first equipment, and the first equipment and the second equipment belong to the preset multicast group;
determining a data communication type, and acquiring target data, wherein the target data is packaged by adopting a preset data format;
and sending the target data to the first equipment based on the network address and the data communication type.
3. The data communication method of claim 2, wherein the data communication type is a first type, and wherein the transmitting the target data to the first device based on the network address and the data communication type comprises:
sending a connection establishment data packet to the first device based on the network address, wherein the connection establishment data packet is used for requesting to establish communication connection with the first device;
when the communication connection with the first equipment is successfully established, serializing the target data into a character string, and determining the character string length of the character string;
transmitting the character string length and the character string to the first device in a binary stream based on the communication connection established with the first device.
4. The data communication method according to claim 3, wherein after the sending of the connection establishment packet to the first device based on the network address, further comprising:
receiving an acknowledgement packet from the first device, the acknowledgement packet indicating that the first device acknowledged establishment of the communication connection with the second device;
and after sending a reply confirmation data packet to the first device, successfully establishing the communication connection with the first device, wherein the reply confirmation data packet represents that the second device receives the confirmation data packet of the first device.
5. The data communication method of claim 2, wherein the data communication type is a second type, and wherein the transmitting the target data to the first device based on the network address and the data communication type comprises:
serializing the target data into a string;
generating a target data packet, wherein the load of the target data packet comprises the character string;
and sending the target data packet to the first equipment based on the network address.
6. The data communication method of claim 2, wherein said determining a data communication type comprises:
monitoring a network state of a target communication network, wherein the target communication network is a communication network in which the first equipment and the second equipment are located;
based on the network status, a data communication type is determined.
7. The data communication method of claim 2, wherein said inquiry packet further carries a communication type parameter, and said determining a data communication type comprises:
determining a data communication type based on the communication type parameter.
8. A data communication apparatus, comprising:
an obtaining unit, configured to obtain an inquiry packet based on a multicast address corresponding to a preset multicast group, where the inquiry packet carries a network address of a first device, and the first device and the second device belong to the preset multicast group;
the device comprises a determining unit, a processing unit and a processing unit, wherein the determining unit is used for determining a data communication type and acquiring target data, and the target data is packaged by adopting a preset data format;
a sending unit, configured to send the target data to the first device based on the network address and the data communication type.
9. An electronic device comprising a processor and a memory, the memory storing a plurality of instructions; the processor loads instructions from the memory to perform the steps of the data communication method according to any one of claims 1 to 7.
10. A computer readable storage medium storing instructions adapted to be loaded by a processor to perform the steps of the data communication method according to any one of claims 1 to 7.
CN202210375351.5A 2022-04-11 2022-04-11 Data communication method, device, electronic equipment and storage medium Active CN114697258B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210375351.5A CN114697258B (en) 2022-04-11 2022-04-11 Data communication method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210375351.5A CN114697258B (en) 2022-04-11 2022-04-11 Data communication method, device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114697258A true CN114697258A (en) 2022-07-01
CN114697258B CN114697258B (en) 2024-07-02

Family

ID=82142681

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210375351.5A Active CN114697258B (en) 2022-04-11 2022-04-11 Data communication method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114697258B (en)

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1933460A (en) * 2006-09-30 2007-03-21 中兴通讯股份有限公司 Equipment, system and realizing method for wireless local network transmission group broadcasting frame
US20100014519A1 (en) * 2007-10-15 2010-01-21 Media Patents, S.L. Methods for managing multicast traffic between sources sending data and hosts requesting data and network equipment used to implement the methods
US20160094353A1 (en) * 2014-09-30 2016-03-31 Vmware, Inc. Technique to submit multicast membership state in absence of querier
CN105657040A (en) * 2016-02-17 2016-06-08 深圳市贝美互动科技有限公司 Inter-device intranet communication method and system
CN108064071A (en) * 2018-02-13 2018-05-22 广东欧珀移动通信有限公司 Method for connecting network, device, storage medium and electronic equipment
US20180219692A1 (en) * 2017-01-27 2018-08-02 Canon Kabushiki Kaisha Communication apparatus, method for controlling communication apparatus, and storage medium
US20180270146A1 (en) * 2017-03-15 2018-09-20 Nicira, Inc. Multicast packet handling in logical networks
WO2019153869A1 (en) * 2018-02-06 2019-08-15 杭州海康威视数字技术股份有限公司 Wifi connection method and apparatus
CN111246400A (en) * 2020-03-31 2020-06-05 上海庆科信息技术有限公司 Signal quality detection method, device, storage medium, electronic device and system
CN112187756A (en) * 2020-09-21 2021-01-05 普联国际有限公司 Multicast data transmission method, device, equipment and storage medium
CN113225697A (en) * 2021-07-07 2021-08-06 中兴通讯股份有限公司 Group user communication method, device, network equipment and storage medium
CN113746945A (en) * 2020-05-30 2021-12-03 华为技术有限公司 Reverse address resolution method and electronic equipment

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1933460A (en) * 2006-09-30 2007-03-21 中兴通讯股份有限公司 Equipment, system and realizing method for wireless local network transmission group broadcasting frame
US20100014519A1 (en) * 2007-10-15 2010-01-21 Media Patents, S.L. Methods for managing multicast traffic between sources sending data and hosts requesting data and network equipment used to implement the methods
US20160094353A1 (en) * 2014-09-30 2016-03-31 Vmware, Inc. Technique to submit multicast membership state in absence of querier
CN105657040A (en) * 2016-02-17 2016-06-08 深圳市贝美互动科技有限公司 Inter-device intranet communication method and system
US20180219692A1 (en) * 2017-01-27 2018-08-02 Canon Kabushiki Kaisha Communication apparatus, method for controlling communication apparatus, and storage medium
US20180270146A1 (en) * 2017-03-15 2018-09-20 Nicira, Inc. Multicast packet handling in logical networks
WO2019153869A1 (en) * 2018-02-06 2019-08-15 杭州海康威视数字技术股份有限公司 Wifi connection method and apparatus
CN108064071A (en) * 2018-02-13 2018-05-22 广东欧珀移动通信有限公司 Method for connecting network, device, storage medium and electronic equipment
CN111246400A (en) * 2020-03-31 2020-06-05 上海庆科信息技术有限公司 Signal quality detection method, device, storage medium, electronic device and system
CN113746945A (en) * 2020-05-30 2021-12-03 华为技术有限公司 Reverse address resolution method and electronic equipment
CN112187756A (en) * 2020-09-21 2021-01-05 普联国际有限公司 Multicast data transmission method, device, equipment and storage medium
CN113225697A (en) * 2021-07-07 2021-08-06 中兴通讯股份有限公司 Group user communication method, device, network equipment and storage medium

Also Published As

Publication number Publication date
CN114697258B (en) 2024-07-02

Similar Documents

Publication Publication Date Title
US20220078864A1 (en) Wireless headphone matching method, device, terminal and charging box
US8095716B2 (en) Method and system for communicating capability information from an accessory to a media player
US11243595B2 (en) Method and apparatus for reducing continuous-wakeup delay of bluetooth loudspeaker, and bluetooth loudspeaker
CN108924274B (en) Domain name system DNS processing method and device, storage medium and electronic equipment
WO2020156432A1 (en) Indication signal transmission method, terminal, and network device
KR20200110086A (en) Method for establishing wireless communication link and electronic device supporting the same
WO2017096909A1 (en) Data connection establishing method and apparatus
CN113157810B (en) Block synchronization method, computer equipment and storage medium
KR102133514B1 (en) Status message service providing method of electronic apparatus and electronic apparatus thereof
US9843527B2 (en) Method for processing data and an electronic device thereof
CN114697258B (en) Data communication method, device, electronic equipment and storage medium
WO2017166093A1 (en) Front-end system
US20210314897A1 (en) Time lnformation Obtaining Method and Transmission Method, Terminal, and Network Device
CN107835238B (en) Method for solving repeated discovery of attribute database
CN114844911B (en) Data storage method, device, electronic equipment and computer readable storage medium
WO2017166095A1 (en) Server front-end method
US12119936B2 (en) Data transmission method, terminal, and network device
CN114095585B (en) Data transmission method, device, storage medium and electronic equipment
WO2020151559A1 (en) Capability information reporting method, precoding matrix indicator feedback method and communication device
CN115378803B (en) Log management method, device, blockchain node and storage medium
WO2017166094A1 (en) Server front-end method
CN114158027B (en) Communication connection method, device, terminal and storage medium
WO2024138503A1 (en) Data encryption method and apparatus, computer device and storage medium
WO2024001134A1 (en) Method and apparatus for connecting audio device, and storage medium and device
US20230046085A1 (en) Dai counting method, dai counting control method, terminal, and network device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant