CN114338479B - Communication method, device and system - Google Patents

Communication method, device and system Download PDF

Info

Publication number
CN114338479B
CN114338479B CN202210002881.5A CN202210002881A CN114338479B CN 114338479 B CN114338479 B CN 114338479B CN 202210002881 A CN202210002881 A CN 202210002881A CN 114338479 B CN114338479 B CN 114338479B
Authority
CN
China
Prior art keywords
connection
connections
communication
client
session
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210002881.5A
Other languages
Chinese (zh)
Other versions
CN114338479A (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.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202210002881.5A priority Critical patent/CN114338479B/en
Publication of CN114338479A publication Critical patent/CN114338479A/en
Application granted granted Critical
Publication of CN114338479B publication Critical patent/CN114338479B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention provides a communication method, a communication device and a communication system. The method is applied to a client, the client comprises a connection pool, and the connection pool comprises a plurality of connections, and the method comprises the following steps: establishing a session with a server through a plurality of connections in a connection pool; selecting connection which is not in an occupied state from a connection pool as a target connection; and carrying out session communication with the server through the target connection. In the mode, the client establishes a plurality of connections with the server through the connection pool, so that the fault tolerance and message throughput of the communication between the client and the server can be increased, and the stability of the communication is enhanced.

Description

Communication method, device and system
Technical Field
The present invention relates to the field of data communications technologies, and in particular, to a communication method, device, and system.
Background
The network communication stability of the Internet of things equipment is an intelligent core problem, when the equipment is communicated with an Internet of things platform at present, the main stream scheme is that the equipment uses an authorized key to establish a single long connection with the platform to realize communication, the scheme uses fewer network resources, the development logic is simpler, and the management of a communication session by a cloud platform is also more convenient. Currently, the mainstream of the industry is IoTHub (Internet of Things Hub, cloud internet of things) communication, and particularly, communication middleware based on MQTT (Message Queuing Telemetry Transport, message queue telemetry transport protocol) protocol mostly adopts a one-device-one-session model, namely a single-device-single-session model.
However, the single device single session model, while simple to implement, has low stability of communication, poor fault tolerance and poor message throughput.
Disclosure of Invention
In view of the above, the present invention is directed to a communication method, device and system, so as to enhance the stability of communication, and improve the fault tolerance and message throughput.
In a first aspect, an embodiment of the present invention provides a communication method, applied to a client, where the client includes a connection pool, and the connection pool includes a plurality of connections, and the method includes: establishing a session with a server through a plurality of connections in a connection pool; selecting connection which is not in an occupied state from a connection pool as a target connection; and carrying out session communication with the server through the target connection.
In a preferred embodiment of the present invention, the method further includes: establishing a plurality of connections based on the capacity of a preset connection pool; and adding the established multiple connections into a connection pool.
In a preferred embodiment of the present invention, the method further includes: respectively sending verification information to a server through a plurality of connections; the verification information comprises a key and a certificate of the client, and the verification information sent by the plurality of connections comprises the same key and certificate of the client; and receiving verification results of the plurality of connections sent by the server.
In a preferred embodiment of the present invention, the method further includes: a preset time wheel model is adopted through a plurality of connections, a heartbeat packet is sent to a server based on a heartbeat interval and the establishment time of a session, and heartbeat data returned by the server are received; and if the heartbeat data corresponding to the first connection is not received within a preset first threshold value, recovering the first connection.
In a preferred embodiment of the present invention, after the step of receiving the heartbeat data returned by the server, the method further includes: determining network response times for the plurality of connections based on the heartbeat data; connections with network response times exceeding a first threshold are reclaimed.
In a preferred embodiment of the present invention, the method further includes: and reconnecting the recovered connection if the number of connections in the connection pool is smaller than a preset second threshold value until the number of connections in the connection pool is equal to the second threshold value.
In a second aspect, an embodiment of the present invention further provides a communication method, which is applied to a server, where the server is in communication connection with a client, and the server includes a plurality of areas, and the plurality of areas include a plurality of communication middleware; the method comprises the following steps: establishing a session with the client over the plurality of connections; distributing a plurality of connections to a plurality of communication middleware in the same area; and carrying out session communication with the client based on the connection in the communication middleware.
In a preferred embodiment of the present invention, the above-mentioned multiple communication middleware for distributing multiple connections to the same area includes: receiving a connection request sent by a client through a plurality of connections; and uniformly distributing the connection corresponding to the homologous connection request to different communication middleware in the same area.
In a preferred embodiment of the present invention, the step of performing session communication with the client based on the connection in the communication middleware includes: receiving a third message of a session sent by any connection of the client, and marking sending equipment of the third message as the client; the connection that is not in the occupied state and that has the least network delay is selected to send a fourth message of the session to the client.
In a preferred embodiment of the present invention, the method further includes: receiving verification information sent by a client through a plurality of connections; the verification information comprises a key and a certificate of the client; verifying the plurality of connections based on the key and the certificate of the client to obtain a plurality of verification results; and sending the verification results to the client through the connections.
In a preferred embodiment of the present invention, the method further includes: receiving heartbeat packets sent by a client through a plurality of connections, and returning heartbeat data through the plurality of connections; wherein the heartbeat data includes network response times for the plurality of connections.
In a preferred embodiment of the present invention, the method further includes: and recording a list of the corresponding relations of the plurality of connections and the plurality of communication middleware.
In a preferred embodiment of the present invention, the step of performing session communication with the client based on the connection in the communication middleware includes: determining a list corresponding to the client; and selecting connection from the list to conduct session communication with the client.
In a preferred embodiment of the present invention, the method further includes: acquiring communication states of a plurality of connections; if the communication states of the plurality of connections are all disconnected, the state of the session is an offline state; if at least one of the communication states of the connection exists is a connected state, the state of the session is an on-line state.
In a third aspect, an embodiment of the present invention further provides a communication device, applied to a client, where the client includes a connection pool, and the connection pool includes a plurality of connections, and the device includes: a first session establishment module for establishing a session with the server through a plurality of connections in the connection pool; the target connection selection module is used for selecting connection which is not in an occupied state from the connection pool as target connection; and the first session communication module is used for carrying out session communication with the server through the target connection.
In a fourth aspect, an embodiment of the present invention further provides a communication device, which is applied to a server, where the server is communicatively connected to a client, and the server includes a plurality of areas, and the plurality of areas include a plurality of communication middleware; the device comprises: a second session establishment module for establishing a session with the client through a plurality of connections; the connection distribution module is used for distributing a plurality of connections to a plurality of communication middleware in the same area; and the second session communication module is used for carrying out session communication with the client based on the connection in the communication middleware.
In a fifth aspect, an embodiment of the present invention further provides a communication system, including a client and a server; the client is used for executing the communication method; the server is used for executing the communication method.
The embodiment of the invention has the following beneficial effects:
according to the communication method, the communication device and the communication system provided by the embodiment of the invention, the client establishes a session with the server through a plurality of connections in the connection pool; and selecting the connection which is not in an occupied state from the connection pool as a target connection to carry out session communication with the server. In the mode, the client establishes a plurality of connections with the server through the connection pool, so that the fault tolerance and message throughput of the communication between the client and the server can be increased, and the stability of the communication is enhanced.
Additional features and advantages of the disclosure will be set forth in the description which follows, or in part will be obvious from the description, or may be learned by practice of the techniques of the disclosure.
The foregoing objects, features and advantages of the disclosure will be more readily apparent from the following detailed description of the preferred embodiments taken in conjunction with the accompanying drawings.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a communication method according to an embodiment of the present invention;
FIG. 2 is a flow chart of another communication method according to an embodiment of the present invention;
FIG. 3 is a flowchart of another communication method according to an embodiment of the present invention;
FIG. 4 is a flowchart of another communication method according to an embodiment of the present invention;
FIG. 5 is a flowchart of another communication method according to an embodiment of the present invention;
FIG. 6 is a flowchart of another communication method according to an embodiment of the present invention;
fig. 7 is a schematic diagram of a main processing flow of a communication system according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a communication device according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of another communication device according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Currently, the mainstream of the industry, namely the IoTHub, especially the communication middleware based on the MQTT protocol, mostly adopts a device-to-session model, namely a single-device-to-single-session model. However, the single device single session model described above, although simple to implement, has the following drawbacks:
1. The session is easily disconnected due to network jitter, although the session reconnection mechanism can be used for compensation, the network connection is established through a plurality of communication handshakes, authentication and permission distribution processes, service logic is more, if the session and the buffer memory are required to be cleaned before the network and the client are restarted, so that the retry time is in the second level, and the service generally requires millisecond-level processing. Therefore, the reconnection time is long (the influence of the device performance is large), the user experience is affected, and the problem of data loss is easy to occur.
2. Single session send messages are blocked while only one message can be sent, multiple messages can be blocked by sequential sending.
3. Message throughput of the device is limited, message transmission of sub-devices of the gateway device is restricted, and message loss of some devices is easy to occur. For example: temperature and humidity sensor and multi-functional gateway must appear in pairs just can upload temperature and humidity data to the high in the clouds.
4. The cloud proxy (Broker) and client need to do a large number of fault tolerance mechanisms and buffering mechanisms to solve the problem of unstable session, but are difficult to eradicate.
Based on the above, the communication method, the device and the system provided by the embodiment of the invention realize a client multi-session strategy, improve the fault tolerance and the message throughput of the communication between the client and the server, and simultaneously optimize the session management mechanism of the communication middleware of the server, so as to improve the communication stability.
For the convenience of understanding the present embodiment, a detailed description will be first provided of a communication method disclosed in the embodiment of the present invention.
The embodiment provides a communication method, which is applied to a client, and the client is in communication connection with a server, referring to a flowchart of the communication method shown in fig. 1, the communication method includes the following steps:
step S100, a session is established with the server through a plurality of connections in the connection pool.
The client in this embodiment may be a device with interaction and communication functions, such as a mobile phone, a computer, a tablet computer, and the server may be a physical server or a cloud server. In this embodiment, the server is generally a cloud server (also referred to as a cloud server), which will not be described herein.
The embodiment can change the original mode of single connection between the client and the server into the mode that the client is connected with the server through the connection pool. Here, the Session (Session) is a Context (Context) between the start of communication and the end of communication. This context is a piece of memory located at the server side: information such as the client device connected this time, which application program is passed through, and which user is logged in is recorded. A Connection is a physical path from a client to an instance. The connection may be established over a network or locally. A connection is typically established between a client process and a dedicated server or a scheduler.
Wherein the session is established simultaneously with the connection, both of which are descriptions of the same thing at different levels. Briefly, a connection is a physical client-to-server communication link and a session is a logical user-to-server communication interaction.
In this embodiment, connections may be sequentially established with the servers according to the order of connections in the connection pool, and the established connections may be placed in the connection pool. The client may then communicate with the server over the connections in the connection pool, for example: transmission and reception of messages. Therefore, the embodiment can change the original single connection mode of the client and the server into the multi-connection mode of the client and the server through the connection pool, so that the fault tolerance and the message throughput of the communication between the client and the server are improved, and the stability of the communication is enhanced.
Step S102, selecting connection which is not in occupied state from the connection pool as target connection.
When the client needs to communicate with the server, unoccupied connection can be randomly acquired from the connection pool to serve as target connection, and communication is carried out through the target connection.
Step S104, the session communication is carried out with the server through the target connection.
For example, a connection in the connection pool that is not in an occupied state is selected to send a first message to a server. The state of each connection in the pool of connections may be determined first, one of the connections that is not in an occupied state may be randomly selected, and a first message may be sent to the server via the selected connection. Or randomly selecting one connection from the connection pool, determining the state of the selected connection, and if the selected connection is not in an occupied state, sending a first message to the server through the selected connection; if the selected connection is in an occupied state, the connection is re-selected from the connection pool.
Similarly, when the server needs to send the downlink message (i.e. the second message), the target connection push message in the idle state may be preferentially selected, for example: the target connection in the idle state is selected to push the second message.
The state of each connection may be determined first, one selected randomly from the connections in idle state, pushing the second message over the selected target connection. Or randomly selecting one connection, determining the state of the selected connection, and pushing a second message through the selected target connection if the selected connection is in an idle state; if the selected connection is not in an idle state, the connection is reselected.
According to the communication method, the communication device and the communication system provided by the embodiment of the invention, the client establishes a session with the server through a plurality of connections in the connection pool; and selecting the connection which is not in an occupied state from the connection pool as a target connection to carry out session communication with the server. In the mode, the client establishes a plurality of connections with the server through the connection pool, so that the fault tolerance and message throughput of the communication between the client and the server can be increased, and the stability of the communication is enhanced.
The present embodiment provides another communication method, which is implemented on the basis of the above embodiment; this example focuses on the specific implementation of establishing a connection. Referring to the flowchart of another communication method shown in fig. 2, the communication method in this embodiment includes the following steps:
step S200, establishing a plurality of connections based on the capacity of the connection pool set in advance.
Specifically, the capacity of the connection pool in the client is predetermined in this embodiment. The capacity of the connection pool characterizes the maximum number of connections that the connection Chi Zhongyun is permitted to exist. For example: the capacity of the connection pool in the client is 30, and 30 connections are allowed at most in the connection pool.
Step S202, adding the established connections into a connection pool.
After each connection is established, the connection can be added into a connection pool of the client, and the connection in the connection pool is uniformly managed and allocated through a connection pool manager.
In step S204, a session is established with the server through a plurality of connections in the connection pool.
Step S206, selecting the connection which is not in the occupied state from the connection pool as the target connection.
In step S208, session communication is performed with the server through the target connection.
In addition, the connections in the connection pool in this embodiment may share the key of the client. I.e. the key of the client can be used by all connections in the connection pool, e.g. the client can be provided to verify in the following way: respectively sending verification information to a server through a plurality of connections; the verification information comprises a key and a certificate of the client, and the verification information sent by the plurality of connections comprises the same key and certificate of the client; and receiving verification results of the plurality of connections sent by the server.
Assuming that the connection pool includes 3 connections A, B, C, during authentication, authentication information including a key and a certificate of the client may be transmitted to the server through three connections A, B, C, respectively, and it should be noted that the key and the certificate of the client included in the authentication information transmitted through the three connections may be the same, that is, the connections may share the key of the client. The server receives the verification information sent through the 3 connections, can verify according to the key and the certificate of the client included in the verification information, and sends the verification result to the client.
Embodiments of the present invention may determine heartbeat data for each connection based on a time-wheel model, for example: a preset time wheel model is adopted through a plurality of connections, a heartbeat packet is sent to a server based on a heartbeat interval and the establishment time of a session, and heartbeat data returned by the server are received; and if the heartbeat data corresponding to the first connection is not received within a preset first threshold value, recovering the first connection.
Each connection in the client independently detects the heartbeat data, and if the heartbeat data corresponding to the first connection is not received within a preset first threshold value, the communication abnormality between the first connection and the server is indicated, and the first connection needs to be recovered. In performing heartbeat detection, the network response time of each may also be detected, for example: determining network response times for the plurality of connections based on the heartbeat data; connections with network response times exceeding a first threshold are reclaimed. If the network response time of a connection exceeds a first threshold, the connection may be considered to have poor communication with the server and may need to be reclaimed.
In this way, the connection with the server communication abnormality can be recovered, so when the recovered connection is more, reconnection may be required, for example: and reconnecting the recovered connection if the number of connections in the connection pool is smaller than a preset second threshold value until the number of connections in the connection pool is equal to the second threshold value.
If the number of connections in the connection pool is less than the preset second threshold, the connections in the connection pool may be considered too few, at which time the recovered connections may be reconnected to increase the number of connections in the connection pool until the number of connections in the connection pool equals the second threshold.
The embodiment also provides a communication method which is applied to the server, wherein the server is in communication connection with the client, the server comprises a plurality of areas, and the plurality of areas comprise a plurality of communication middleware. Based on the above description, referring to a flowchart of another communication method shown in fig. 3, the communication method includes the steps of:
step S300, a session is established with the client through a plurality of connections.
In step S302, a plurality of connections are allocated to a plurality of communication middleware in the same area.
The communication middleware of the embodiment may be an io thub Broker, and a load balancing policy may be added in the communication middleware to allocate multiple sessions of the same client to different broaders in the same area to establish connection.
Step S304, the session communication is carried out with the client based on the connection in the communication middleware.
When the session communication is carried out, the server can communicate with the client through the connection in the communication middleware, so that the session communication can be carried out through a plurality of connections at the same time, and the message processing capacity of the communication middleware is improved.
According to the communication method provided by the embodiment of the invention, a plurality of communication middleware in the same area can be used for establishing a plurality of connections with the client, so that the advantages of cloud cluster are exerted, and the message processing capacity of the communication middleware is improved through uplink and downlink separation of communication, so that the experience of a user is improved.
The present embodiment provides another communication method, which is implemented on the basis of the above embodiment; this embodiment focuses on the specific implementation of multiple communication middleware that distributes multiple connections to the same area. Referring to the flowchart of another communication method shown in fig. 4, the communication method in this embodiment includes the following steps:
step S400, a connection request sent by a client through a plurality of connections is received.
In this embodiment, the service logic of the server for processing the uplink and downlink messages and session authentication is kept unchanged, so as to keep the reusability of the Broker code.
Step S402, the connection corresponding to the homologous connection request is uniformly distributed to different communication middleware in the same area.
Referring to the overall architecture diagram of a communication system shown in fig. 5, the iothumb can adjust the load policy to uniformly distribute the connection requests of the same source (same IP address and port) to different broaders instead of focusing on the same broaders, so as to avoid single-point risk.
In addition, the embodiment may record a list of communication middleware that establishes a connection with the client, for example: and recording a list of the corresponding relations of the plurality of connections and the plurality of communication middleware. The above list may be referred to as a Broker list, so as to facilitate selecting a communication middleware from the Broker list to communicate with the client, for example: determining a list corresponding to the client; and selecting connection from the list to conduct session communication with the client.
In step S404, a session is established with the client through a plurality of connections.
In step S406, the plurality of connections are allocated to a plurality of communication middleware in the same area.
In step S408, session communication is performed with the client based on the connection in the communication middleware.
Specifically, the session communication may be performed through the following steps: receiving a third message of a session sent by any connection of the client, and marking sending equipment of the third message as the client; the connection that is not in the occupied state and that has the least network delay is selected to send a fourth message of the session to the client.
And the device marks the uplink message of the session from any third message which is sent to the cloud end by any connection, and marks the source of the third message as a client. When the cloud end needs to send a fourth message to the client end, judging whether the session corresponds to the target equipment according to a subscription list of the session, if so, calling a connection selector to obtain a connection list, selecting a downlink type connection from the connection list, sending the fourth message by taking the connection which is unoccupied and has the minimum network delay, and releasing the connection after the fourth message is successfully sent.
Specifically, the method further comprises the following steps: obtaining verification information sent by a receiving client through a plurality of connections; the verification information comprises a key and a certificate of the client; verifying the plurality of connections based on the key and the certificate of the client to obtain a plurality of verification results; and sending the verification results to the client through the connections.
In this embodiment, the communication middleware independently authenticates, and the session independently detects the heartbeat state. Independent authentication means that a plurality of broaders only authenticate the connection established by the broaders, and the authentication states of other broaders are not needed to be considered; a session is simply understood as a set of data that records the identity of a client, and a shared session refers to that when a client establishes a connection with multiple broaders, only one list is created, and all broaders can access the list to obtain information such as the identity of the client.
Specifically, the method further comprises the following steps: acquiring communication states of a plurality of connections; if the communication states of the plurality of connections are all disconnected, the state of the session is an offline state; if at least one of the communication states of the connection exists is a connected state, the state of the session is an on-line state.
In this embodiment, the key is used as a unit, and the connections of the same key are unified and integrated into the same target session, so that the session state is shared, that is, when all the connections are disconnected, the session state becomes offline, otherwise, the session state is online. The multiple connection attributes in the session may maintain necessary information such as home Broker, channel number, connection status, last heartbeat network delay, etc.
Specifically, the method further comprises the following steps: receiving heartbeat packets sent by a client through a plurality of connections, and returning heartbeat data through the plurality of connections; wherein the heartbeat data includes network response times for the plurality of connections.
The client can respectively send heartbeat packets through a plurality of connections, the server can determine heartbeat data of each connection according to the received heartbeat packets and return the heartbeat data to the server through corresponding connections, wherein the heartbeat data comprises network response time of the plurality of connections, and the client can determine the network response time of each connection according to the heartbeat data.
The method provided by the embodiment of the invention can change single-channel communication into multi-channel selection through component transformation by the strategy, and greatly improves the communication reliability and the message throughput. The embodiment of the invention realizes a client multi-session strategy, can improve the fault tolerance and message throughput of the communication between the client and the server, and simultaneously optimizes the session management mechanism of the communication middleware of the server, thereby improving the communication stability.
The embodiment also provides a communication system, which comprises a client and a server; the client is used for the communication method; the server is used for executing the communication method. Referring to the flowchart of another communication method shown in fig. 6, the communication method includes the steps of:
Specifically, the client of the communication system includes a connection pool manager, where the connection pool manager includes at least one of the following: a pool configuration component, a session initializer, a key management component, a session selector, a heartbeat management component, a connection reconnection component, a network detection component, a connection reclamation component, and a message callback component.
Referring to the overall architecture diagram of a communication system shown in fig. 5 and the main process flow diagram of a communication system shown in fig. 7, the core of the client part is a connection pool manager, which is the essential content of the client of the present invention and is also the main component of the client communication. Can mainly comprise several core components:
1. pool configuration component: the related parameters of the primary user management connection pool initialization include pool management parameters such as pool size, heartbeat interval, heartbeat packet message format, session timeout time and the like.
2. Session initializer: and the session is initialized according to the connection pool, and two kinds of synchronous initialization and asynchronous initialization are supported. The synchronous initialization means that the sessions are established one by one, and the next session is established only after the previous session is established successfully; asynchronous initialization refers to the start of the establishment of the next session without waiting for the success of the last session establishment.
3. Key management: is responsible for managing keys and certificates required for establishing sessions.
4. Session selector: the connection pool provides standard APIs (Application Programming Interface, application program interfaces) to the outside, the logic outside the pool only needs to call the selector method, and the connection pool automatically returns idle or low-delay sessions to the calling party for communication.
5. Heartbeat management: and the heartbeat manager marks the thread for recycling if the platform does not normally return the heartbeat response. The time wheel model refers to a scheduling model for efficiently managing timing tasks in batches. Typically implemented as a ring structure, resembling a clock, divided into a number of slots, one slot representing a time interval, the slots storing timing tasks using doubly linked lists. The pointers of the time wheel model periodically jump to one slot, and the timing task of the slot is executed.
6. And (3) connection reconnection: and the connection reconnection when the connection in the pool is lower than the initialized connection number is processed until the number of active connections is equal to the number of sessions configured by the pool.
7. Network detection: the network response time of each connection is measured based on the message response such as heartbeat, and when the response time exceeds a configuration threshold, the connection is marked and reclaimed by the reclaimer.
8. And (3) connection recovery: the connection marked in the checking pool is responsible for destroying the original connection; in addition, the occupied state of the contact connection after the connection is logically returned is processed due to the connection call called by the service logic in the session selector.
9. Message callback: is responsible for receiving messages sent to the device and informing other business logic to process the message.
In summary, the communication method, the device and the system provided by the embodiment of the invention make up the problem of unstable communication through session redundancy and keep good communication quality; the network link state from the equipment to the cloud can be obtained, and the operation and maintenance monitoring is convenient; the advantage of cloud cluster can be exerted, and the message processing capability of a Broker is improved through uplink and downlink separation of communication.
Corresponding to the embodiment of the method, the embodiment of the invention provides a communication device which is applied to a client, and the client is in communication connection with a server; referring to fig. 8, a schematic structural diagram of a communication device includes:
A first session establishment module 81 for establishing a session with the server through a plurality of connections in the connection pool;
a target connection selection module 82, configured to select a connection that is not in an occupied state from the connection pool as a target connection;
the first session communication module 83 is configured to perform session communication with the server through the target connection.
According to the communication device provided by the embodiment of the invention, a client establishes a session with a server through a plurality of connections in a connection pool; and selecting the connection which is not in an occupied state from the connection pool as a target connection to carry out session communication with the server. In the mode, the client establishes a plurality of connections with the server through the connection pool, so that the fault tolerance and message throughput of the communication between the client and the server can be increased, and the stability of the communication is enhanced.
The device further comprises: a first connection establishment module for establishing a plurality of connections based on a capacity of a connection pool set in advance; and adding the established multiple connections into a connection pool.
The device further comprises: the first connection verification module is used for respectively sending verification information to the server through a plurality of connections; the verification information comprises a key and a certificate of the client, and the verification information sent by the plurality of connections comprises the same key and certificate of the client; and receiving verification results of the plurality of connections sent by the server.
The device further comprises: the first heartbeat detection module is used for sending a heartbeat packet to the server based on the heartbeat interval and the establishment time of the session by adopting a preset time wheel model through a plurality of connections and receiving heartbeat data returned by the server; and if the heartbeat data corresponding to the first connection is not received within a preset first threshold value, recovering the first connection.
The first heartbeat detection module is further configured to determine network response times of a plurality of connections based on heartbeat data; connections with network response times exceeding a first threshold are reclaimed.
The device further comprises: and the first connection reconnection module is used for reconnecting the recovered connection if the number of the connections in the connection pool is smaller than a preset second threshold value until the number of the connections in the connection pool is equal to the second threshold value.
Corresponding to the embodiment of the method, the embodiment of the invention also provides another communication device which is applied to the server, wherein the server is in communication connection with the client, the server comprises a plurality of areas, and the plurality of areas comprise a plurality of communication middleware; referring to fig. 9, another communication device is shown, which includes:
a second session establishment module 91, configured to establish a session with the client through a plurality of connections;
A connection allocation module 92 for allocating a plurality of connections to a plurality of communication middleware in the same area;
a second session communication module 93, configured to perform session communication with the client based on the connection in the communication middleware.
The communication device provided by the embodiment of the invention can establish a plurality of connections with the client by using a plurality of communication middleware in the same area. Therefore, the cloud cluster advantage is exerted, and the message processing capability of the communication middleware is improved through the uplink and downlink separation of communication, so that the experience of a user is improved.
The connection allocation module is used for receiving connection requests sent by the client through a plurality of connections; and uniformly distributing the connection corresponding to the homologous connection request to different communication middleware in the same area.
The second session communication module is configured to receive a third message of a session sent by any connection of the client, and mark a sending device of the third message as the client; the connection that is not in the occupied state and that has the least network delay is selected to send a fourth message of the session to the client.
The device further comprises: the second connection verification module is used for receiving verification information sent by the client through a plurality of connections; the verification information comprises a key and a certificate of the client; verifying the plurality of connections based on the key and the certificate of the client to obtain a plurality of verification results; and sending the verification results to the client through the connections.
The device further comprises: the second heartbeat detection module is used for receiving heartbeat packets sent by the client through a plurality of connections and returning heartbeat data through the plurality of connections; wherein the heartbeat data includes network response times for the plurality of connections.
The device further comprises: and the list recording module is used for recording the list of the corresponding relation between the plurality of connections and the plurality of communication middleware.
The second session communication module is configured to determine a list corresponding to the client; and selecting connection from the list to conduct session communication with the client.
The device further comprises: a session state determining module, configured to obtain communication states of a plurality of connections; if the communication states of the plurality of connections are all disconnected, the state of the session is an offline state; if at least one of the communication states of the connection exists is a connected state, the state of the session is an on-line state.
The implementation principle and the technical effects of the communication device provided by the embodiment of the present invention are the same as those of the foregoing communication method embodiment, and for brevity, reference may be made to the corresponding content in the foregoing communication method embodiment where the embodiment of the communication device is not mentioned.
The embodiment of the invention also provides electronic equipment for running the communication method; referring to fig. 10, an electronic device includes a memory 100 and a processor 101, where the memory 100 is configured to store one or more computer instructions, and the one or more computer instructions are executed by the processor 101 to implement the above-mentioned communication method.
Further, the electronic device shown in fig. 10 further includes a bus 102 and a communication interface 103, and the processor 101, the communication interface 103, and the memory 100 are connected through the bus 102.
The memory 100 may include a high-speed random access memory (RAM, random Access Memory), and may further include a non-volatile memory (non-volatile memory), such as a plurality of disk memories. Communication connection between the system network element and a plurality of other network elements is achieved through a plurality of communication interfaces 103 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like may be used. Bus 102 may be an ISA bus, a PCI bus, an EISA bus, or the like. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, only one bi-directional arrow is shown in FIG. 10, but not only one bus or type of bus.
The processor 101 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 101 or instructions in the form of software. The processor 101 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processor, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software modules in a decoding processor. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in the memory 100 and the processor 101 reads information in the memory 100 and in combination with its hardware performs the steps of the method of the previous embodiments.
The embodiment of the invention also provides a computer readable storage medium, which stores computer executable instructions that when being called and executed by a processor, cause the processor to implement the above communication method, and the specific implementation can be referred to the method embodiment and will not be described herein.
The computer program product of the communication method, apparatus and system provided in the embodiments of the present invention includes a computer readable storage medium storing program codes, where the instructions included in the program codes may be used to execute the method in the foregoing method embodiment, and specific implementation may refer to the method embodiment and will not be described herein.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system and/or apparatus may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
In addition, in the description of embodiments of the present invention, unless explicitly stated and limited otherwise, the terms "mounted," "connected," and "connected" are to be construed broadly, and may be, for example, fixedly connected, detachably connected, or integrally connected; can be mechanically or electrically connected; can be directly connected or indirectly connected through an intermediate medium, and can be communication between two elements. The specific meaning of the above terms in the present invention will be understood in specific cases by those of ordinary skill in the art.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In the description of the present invention, it should be noted that the directions or positional relationships indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. are based on the directions or positional relationships shown in the drawings, are merely for convenience of describing the present invention and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a specific orientation, be configured and operated in a specific orientation, and thus should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above examples are only specific embodiments of the present invention, and are not intended to limit the scope of the present invention, but it should be understood by those skilled in the art that the present invention is not limited thereto, and that the present invention is described in detail with reference to the foregoing examples: any person skilled in the art may modify or easily conceive of the technical solution described in the foregoing embodiments, or perform equivalent substitution of some of the technical features, while remaining within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention, and are intended to be included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (17)

1. A method of communication, for use with a client, the client comprising a connection pool, the connection pool comprising a plurality of connections, the method comprising:
establishing a session with a server through a plurality of the connections in the connection pool, so that the server distributes a plurality of the connections which are homologous to a plurality of communication middleware in the same area;
Selecting connection which is not in an occupied state from the connection pool as a target connection;
and carrying out communication of the session with the server through the target connection.
2. The method according to claim 1, wherein the method further comprises:
establishing a plurality of connections based on the preset capacity of the connection pool;
and adding the established plurality of connections into the connection pool.
3. The method according to claim 1, wherein the method further comprises:
respectively sending verification information to the server through a plurality of the connections; the verification information comprises keys and certificates of the clients, and the verification information sent by the plurality of connections comprises the same keys and certificates of the clients;
and receiving verification results of a plurality of connections sent by the server.
4. The method according to claim 1, wherein the method further comprises:
a preset time wheel model is adopted through a plurality of connections, a heartbeat packet is sent to the server based on a heartbeat interval and the establishment time of the session, and heartbeat data returned by the server are received;
and if the heartbeat data corresponding to the first connection is not received within a preset first threshold value, recovering the first connection.
5. The method of claim 4, wherein after the step of receiving heartbeat data returned by the server, the method further comprises:
determining network response times for a plurality of the connections based on the heartbeat data;
and recovering the connection with the network response time exceeding the first threshold.
6. The method according to claim 4 or 5, characterized in that the method further comprises:
and reconnecting the recovered connection if the number of connections in the connection pool is smaller than a preset second threshold value until the number of connections in the connection pool is equal to the second threshold value.
7. The communication method is characterized by being applied to a server, wherein the server is in communication connection with a client, the server comprises a plurality of areas, and the plurality of areas comprise a plurality of communication middleware; the method comprises the following steps:
establishing a session with the client over a plurality of connections;
distributing a plurality of homologous connections to a plurality of communication middleware in the same area;
and carrying out the communication of the session with the client based on the connection in the communication middleware.
8. The method of claim 7, wherein assigning a homologous plurality of said connections to a plurality of said communication middleware in a same area comprises:
Receiving connection requests sent by the client through a plurality of connections;
and uniformly distributing the connection corresponding to the connection request in the same source to different communication middleware in the same area.
9. The method of claim 7, wherein the step of communicating the session with the client based on the connection in the communication middleware comprises:
receiving a third message of the session sent by any connection of the client, and marking a sending device of the third message as the client;
selecting the connection that is not in an occupied state and that has the least network delay to send a fourth message of the session to the client.
10. The method of claim 7, wherein the method further comprises:
receiving verification information sent by the client through a plurality of connections; wherein the authentication information includes a key and a certificate of the client;
verifying a plurality of connections based on the key and the certificate of the client to obtain a plurality of verification results;
and sending a plurality of verification results to the client through a plurality of connections.
11. The method of claim 7, wherein the method further comprises:
Receiving heartbeat packets sent by the client through a plurality of connections, and returning heartbeat data through the connections; wherein said heartbeat data comprises network response times for a plurality of said connections.
12. The method of claim 7, wherein the method further comprises:
and recording a list of the corresponding relations between the plurality of connections and the plurality of communication middleware.
13. The method of claim 12, wherein the step of communicating the session with the client based on the connection in the communication middleware comprises:
determining a list corresponding to the client;
and selecting the connection from the list to communicate with the client for the session.
14. The method of claim 7, wherein the method further comprises:
acquiring a plurality of communication states of the connection;
if the communication states of the plurality of connections are all disconnected, the state of the session is an offline state;
if at least one communication state of the connection exists, the state of the session is an on-line state.
15. A communication device for use with a client, the client comprising a connection pool, the connection pool comprising a plurality of connections, the device comprising:
A first session establishment module, configured to establish a session with a server through a plurality of the connections in the connection pool, so that the server distributes a plurality of the connections that are homologous to a plurality of communication middleware in the same area;
a target connection selection module, configured to select, from the connection pool, a connection that is not in an occupied state as a target connection;
and the first session communication module is used for communicating the session with the server through the target connection.
16. A communication device, characterized by being applied to a server, wherein the server is in communication connection with a client, the server comprises a plurality of areas, and a plurality of areas comprise a plurality of communication middleware; the device comprises:
a second session establishment module for establishing a session with the client through a plurality of connections;
the connection allocation module is used for allocating a plurality of homologous connections to a plurality of communication middleware in the same area;
and the second session communication module is used for carrying out the session communication with the client based on the connection in the communication middleware.
17. A communication system, comprising a client and a server; wherein the client is configured to perform the communication method of any one of claims 1-6; the server is configured to perform the communication method of any of claims 7-14.
CN202210002881.5A 2022-01-04 2022-01-04 Communication method, device and system Active CN114338479B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210002881.5A CN114338479B (en) 2022-01-04 2022-01-04 Communication method, device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210002881.5A CN114338479B (en) 2022-01-04 2022-01-04 Communication method, device and system

Publications (2)

Publication Number Publication Date
CN114338479A CN114338479A (en) 2022-04-12
CN114338479B true CN114338479B (en) 2024-03-22

Family

ID=81021955

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210002881.5A Active CN114338479B (en) 2022-01-04 2022-01-04 Communication method, device and system

Country Status (1)

Country Link
CN (1) CN114338479B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101977234A (en) * 2010-11-02 2011-02-16 中南大学 Parallel TCP (Transmission Control Protocol) technology based wide area network (WAN) communication acceleration method
CN105991305A (en) * 2015-01-28 2016-10-05 中国移动通信集团四川有限公司 Method and device of identifying link abnormity
CN106209945A (en) * 2015-05-07 2016-12-07 阿里巴巴集团控股有限公司 Based on multi-link data transmission method for uplink and device
CN111031094A (en) * 2019-11-06 2020-04-17 远景智能国际私人投资有限公司 Data transmission method, device, equipment and storage medium in IoT system
CN111770157A (en) * 2020-06-24 2020-10-13 广东浪潮大数据研究有限公司 Business processing method and device, electronic equipment and storage medium
CN112104720A (en) * 2020-09-03 2020-12-18 国电南瑞科技股份有限公司 MQTT double-Broker data interaction method and system suitable for edge Internet of things terminal

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10432351B2 (en) * 2017-10-17 2019-10-01 Aagey Holding, LLC Computer network system and method to reduce network latency with a pool of ready connections

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101977234A (en) * 2010-11-02 2011-02-16 中南大学 Parallel TCP (Transmission Control Protocol) technology based wide area network (WAN) communication acceleration method
CN105991305A (en) * 2015-01-28 2016-10-05 中国移动通信集团四川有限公司 Method and device of identifying link abnormity
CN106209945A (en) * 2015-05-07 2016-12-07 阿里巴巴集团控股有限公司 Based on multi-link data transmission method for uplink and device
CN111031094A (en) * 2019-11-06 2020-04-17 远景智能国际私人投资有限公司 Data transmission method, device, equipment and storage medium in IoT system
CN111770157A (en) * 2020-06-24 2020-10-13 广东浪潮大数据研究有限公司 Business processing method and device, electronic equipment and storage medium
CN112104720A (en) * 2020-09-03 2020-12-18 国电南瑞科技股份有限公司 MQTT double-Broker data interaction method and system suitable for edge Internet of things terminal

Also Published As

Publication number Publication date
CN114338479A (en) 2022-04-12

Similar Documents

Publication Publication Date Title
US9300733B2 (en) System and/or method for client-driven server load distribution
US7984492B2 (en) Methods and apparatus for policy enforcement in a wireless communication system
US7072354B1 (en) Token registration of managed devices
US7509394B2 (en) Method for controlling flow of radius protocol
CN110855792B (en) Message pushing method, device, equipment and medium
US20050175027A1 (en) System and method for requesting and granting access to a network channel
US8601568B2 (en) Communication system for authenticating or relaying network access, relaying apparatus, authentication apparatus, and communication method
KR102580332B1 (en) Method and Apparatus for Controlling Congestion in Communication Systems with Services
CN107979539B (en) Message processing method and device
CN110808948B (en) Remote procedure calling method, device and system
WO2011020363A1 (en) Method and system for realizing load balance and diameter client
CN108347350B (en) Communication method and device
CN114338063A (en) Message queue system, service processing method, and computer-readable storage medium
CN110661673B (en) Heartbeat detection method and device
CN114338479B (en) Communication method, device and system
CN111064768B (en) Printer data transmission control method, device, equipment and storage medium
CN114584558B (en) Cloud edge cooperative distributed API gateway system and API calling method
US20220385501A1 (en) User Management Device, BNG, and BNG User Internet Access Method and System
CN111240867B (en) Information communication system and method
CN111490997B (en) Task processing method, proxy system, service system and electronic equipment
CN114745221B (en) Modbus communication system and communication method
KR20160054004A (en) Method and device for application management
CN114143334B (en) Terminal control method and device
CN114095976B (en) Distribution method and device of network slices, electronic equipment and readable medium
JP2017034562A (en) Communication device and reconnection method

Legal Events

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