CN118301133A - Real-time communication method, device, equipment and readable storage medium - Google Patents
Real-time communication method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN118301133A CN118301133A CN202410357705.2A CN202410357705A CN118301133A CN 118301133 A CN118301133 A CN 118301133A CN 202410357705 A CN202410357705 A CN 202410357705A CN 118301133 A CN118301133 A CN 118301133A
- Authority
- CN
- China
- Prior art keywords
- data packet
- server
- client server
- client
- message
- 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
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L65/00—Network arrangements, protocols or services for supporting real-time applications in data packet communication
- H04L65/1066—Session management
- H04L65/1069—Session establishment or de-establishment
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Business, Economics & Management (AREA)
- General Business, Economics & Management (AREA)
- Multimedia (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The application relates to a real-time communication method, a device, equipment and a readable storage medium, wherein the method comprises the following steps: for each client server, receiving a first data packet sent by the client server based on the short connection established with the client server, and acquiring a first matching parameter corresponding to the first data packet; for each client server, forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server; receiving second data packets returned by the server side server, and obtaining second matching parameters corresponding to the second data packets; and based on the first matching parameters and the second matching parameters, sending each second data packet to the corresponding client server. The application accurately forwards the second data packets from different server-side servers to the corresponding client-side servers, thereby realizing the purpose of converting the communication mode of the client-side servers from asynchronous to synchronous and improving the communication efficiency.
Description
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a real-time communication method, apparatus, device, and readable storage medium.
Background
With the rapid development of information technology and the continuous expansion of enterprise business, the communication demands between clients and servers are increasing, and the communication modes also show a diversified trend. In practical applications, the client is a device for sending a data request, the server is a device for providing a service corresponding to the data request, and the client and the server generally communicate in an asynchronous simplex long connection mode, where the asynchronous simplex long connection needs to separate a receiving process and a sending process in a communication process, that is, the client and the server both need to use a receiver for completing the receiving of the data and a transmitter for completing the sending of the data.
In asynchronous simplex long connection communication, the division of the work of a transmitter and a receiver in the devices of the two communication parties is clear, and data can only be transmitted to the corresponding receiver of the other device in one way by the transmitter. In the scene of a plurality of clients, frequent requests and short connection duration, the asynchronous simplex long connection between the clients and the server can cause the waste of communication resources, increase the complexity of communication between the clients and the server, and reduce the communication efficiency between the clients and the server.
Disclosure of Invention
In order to reduce the waste of communication resources, reduce the complexity of a communication system and improve the communication efficiency, the application provides a real-time communication method, a device, equipment and a readable storage medium.
In a first aspect, the present application provides a real-time communication method, including:
For each client server, receiving a first data packet sent by the client server based on a short connection established with the client server, and acquiring a first matching parameter corresponding to the first data packet, wherein the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet;
forwarding, for each of the client servers, the first data packet to the server corresponding to the client server based on the long connection established with at least one server;
receiving at least one second data packet returned by the server, and obtaining second matching parameters corresponding to each second data packet, wherein the second data packet is data responding to the data request, and the second matching parameters are parameters representing response identification of the data request in the second data packet;
And sending each second data packet to a corresponding client server based on at least one first matching parameter and at least one second matching parameter.
The beneficial effects of the invention are as follows: the processing and forwarding of the first data packet and the second data packet are realized by establishing a short connection with the client server and a long connection with the server. Through the first matching parameters and the second matching parameters, the electronic equipment can accurately forward the second data packets from different server-side servers to the corresponding client-side servers, ensure the synchronism of the data, realize the purpose of converting the communication mode of the client-side servers from asynchronous to synchronous, improve the communication efficiency, reduce the waste of communication resources and reduce the complexity of a communication system.
Further, the first matching parameter includes a first message primary key, and the first data packet corresponds to a first message; for each client server, after the obtaining the first matching parameter corresponding to the first data packet, the method further includes:
for each client server, checking the correctness of the first message primary key and the first message;
And if the primary key of the first message and the first message pass verification, executing the step of forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server.
The beneficial effects of adopting the further scheme are as follows: by checking the correctness of the primary key of the first message and the first message, the check item corresponding to the first data packet can be ensured to accord with the corresponding rule, and the integrity and the validity of the first data packet are ensured.
Further, after the forwarding the first data packet to the server corresponding to the client server, the method further includes:
for each client server, calling a public cache to perform blocking waiting corresponding to the client server, wherein the blocking waiting comprises a key value, and the key value is the primary key of the first message;
for each second data packet, the second matching parameters include a second report Wen Zhujian, and after the second matching parameters corresponding to each second data packet are obtained, the method further includes:
For each second data packet, storing a second message primary key corresponding to the second data packet into the public cache;
The sending each second data packet to the corresponding client server based on at least one first matching parameter and at least one second matching parameter includes:
And for each second data packet, acquiring a first message primary key consistent with a second message primary key corresponding to the second data packet in the public cache, taking a client server corresponding to the first message primary key as a server matched with the second data packet, ending blocking waiting corresponding to the client server, and sending the second data packet to the client server.
The beneficial effects of adopting the further scheme are as follows: the public buffer supports concurrent access and parallel processing, and the matching of a plurality of second message main keys and a plurality of first message main keys can be simultaneously carried out in the public buffer, so that the matching speed is improved. And according to the consistency matching condition of the second message main key and the first message main key, the matching of the client server and the returned second data packet is completed, and the correctness matching of the second data packet of the asynchronous simplex long connection is realized.
Further, the blocking waiting further includes waiting for a timeout time, and after the forwarding the first data packet to the server corresponding to the client server, the blocking waiting further includes:
For each client server, judging whether the waiting time of the blocking waiting exceeds the waiting timeout time; and if the waiting timeout time is exceeded, sending timeout prompt information to the client server.
The beneficial effects of adopting the further scheme are as follows: the client is convenient to take relevant processing, so that the possibility that excessive blocking waiting threads wait for matching for a long time is reduced, and the possibility that a processing system corresponding to the electronic equipment is killed is reduced.
Further, before forwarding the first data packet to the server corresponding to the client server based on the long connection established with the at least one server, the method further includes:
For each client server, acquiring the complete length corresponding to the first data packet based on a preset message rule; judging whether the first data packet is complete or not based on the complete length; and if so, executing the step of forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server.
The beneficial effects of adopting the further scheme are as follows: the possibility of the phenomenon of sticking packets when sending the message is reduced.
Further, after receiving the second data packet returned by the at least one server, the method further includes:
Judging whether each second data packet is a heartbeat packet or not; if yes, discarding the second data packet; and if not, executing the step of acquiring the second matching parameters corresponding to each second data packet.
The beneficial effects of adopting the further scheme are as follows: the heartbeat packet is directly abandoned and not processed, so that the heartbeat packet without actual data content is prevented from being further processed, the processing load of the electronic equipment is reduced, and the processing efficiency is improved.
Further, for each of the client servers, before forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server, the method further includes:
For each client server, detecting whether a long connection exists between the client server and the corresponding server; if not, the long connection is reestablished.
The beneficial effects of adopting the further scheme are as follows: by detecting whether the long connection with the client server is normal or not, the first data packet is sent after the long connection is established successfully, and the possibility of communication failure between the electronic equipment and the client server is reduced.
In a second aspect, the present application provides a real-time communication device, comprising:
The first receiving and acquiring module is used for receiving a first data packet sent by the client server based on the short connection established with the client server for each client server, and acquiring a first matching parameter corresponding to the first data packet, wherein the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet;
The forwarding module is used for forwarding the first data packet to the server corresponding to the client server based on the long connection established between the client server and at least one server;
The second receiving and acquiring module is used for receiving at least one second data packet returned by the server side server, acquiring second matching parameters corresponding to each second data packet, wherein the second data packet is data responding to the data request, and the second matching parameters are parameters representing response identification of the data request in the second data packet;
and the sending module is used for sending each second data packet to the corresponding client server based on at least one first matching parameter and at least one second matching parameter.
In a third aspect, the present application provides an electronic device comprising a processor and a memory, the processor being coupled to the memory;
the processor is configured to execute a computer program stored in the memory to cause the electronic device to perform the method according to any one of the first aspects.
In a fourth aspect, the present application provides a computer readable storage medium comprising a computer program or instructions which, when run on a computer, cause the computer to perform the method of any of the first aspects.
Drawings
FIG. 1 is a flow chart of a real-time communication method according to an embodiment of the application;
FIG. 2 is a block diagram of a real-time communication device according to an embodiment of the present application;
fig. 3 is a block diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the accompanying drawings.
The embodiment of the application provides a real-time communication method which can be executed by equipment, wherein the equipment can be a server or terminal equipment, the server can be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, and a cloud server for providing cloud computing service. The terminal device may be, but is not limited to, a smart phone, a tablet computer, a desktop computer, etc.
As shown in fig. 1, a real-time communication method uses an electronic device as an execution subject, and the main flow of the method is described as follows (steps S101 to S104):
Step S101: for each client server, based on the short connection established with the client server, a first data packet sent by the client server is received, a first matching parameter corresponding to the first data packet is obtained, the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet.
Step S102: and forwarding the first data packet to the corresponding server of the client server based on the long connection established with at least one server for each client server.
In this embodiment, the client server is a device that invokes an electronic device and sends a data request, the server is a target server that interacts with the client server, and is configured to provide a service corresponding to the data request for the client server, where the data request is a request for providing relevant data to the client server, and the server may be an union server, and the data request corresponding to the client server may be an union server.
The electronic equipment supports short connection and long connection at the same time, and the short connection is a network communication mode and is mainly characterized in that after each data interaction is completed, both communication parties are disconnected. Compared with long connection, short connection does not maintain a durable connection state, and is suitable for scenes with infrequent data interaction. In short connections, because the connection is temporary, some unnecessary resource occupation can be reduced, and the system corresponding to the client server can be simpler and easier to use. In this embodiment, the electronic device may support multiple conventional short connections such as http and socket at the same time.
The long connection is a way of communicating with a network different from the short connection, and after the electronic device establishes the long connection with the server, if no data packet is sent, both sides need to maintain the connection. Long connections are suitable for frequent, point-to-point communications. In this embodiment, the long connection between the electronic device and the server may be an asynchronous simplex long connection, in which the receiving and transmitting are performed by two different procedures, and simplex communication is characterized in that the sender and the receiver in the two communication devices are separately and definitely configured, and only data can be transmitted in a single fixed direction from the sender to the receiver.
In this embodiment, a configuration file for establishing connection with a client server and a server is stored in the electronic device, where the configuration file includes a short connection port, a local long connection port, and addresses and ports corresponding to the server, and the server may be multiple.
And when the electronic equipment is started, the configuration file is read, the address and the port corresponding to the server can be obtained, and the electronic equipment establishes long connection according to the address and the port corresponding to the server. The address configuration scheme of the asynchronous simplex long connection includes four long connection schemes of a-A1, B-B1, C-C1 and D-D1, when the electronic device is started, a local address corresponding to the electronic device is obtained, and when the local address is determined to be a, a long connection from the electronic device a to the server A1 is established.
In this embodiment, when the client server needs to establish a short connection with the electronic device, the client server needs to send a short connection request to a short connection port corresponding to the electronic device, and according to the short connection request, establish a short connection between the electronic device and the client server.
The configuration file further includes a first corresponding relationship between the short connection port and the local long connection port and a second corresponding relationship between the local long connection port and the port corresponding to the server, and after the electronic device is started, the long connection between the local long connection port and the port corresponding to the server can be established according to the local long connection port and the second corresponding relationship. The client side server can select a short connection port in the electronic equipment for establishing short connection according to the data request, and the electronic equipment obtains a corresponding local long connection port according to the first corresponding relation and the short connection port, so that a server side server corresponding to the client side server is obtained through the local long connection port.
In this embodiment, the first matching parameter includes a first message primary key (first key). If the short connection between the electronic device and the client server is an http short connection, the first matching parameter and the first two parameters of the first message (first data) can be directly obtained from a request body corresponding to the http short connection. The request body (request body) is a part of the http short connection, which is used for carrying data sent to the electronic device, the client server sends the data to the electronic device in the request body, and the electronic device can read and parse the required first message primary key (first key) and the first message (first data) from the request body.
If the short connection between the electronic equipment and the client server is a socket short connection, the electronic equipment can firstly acquire a message header of data sent by the client server, then analyze the message length according to the message header, and then read the complete message according to the message length; once the complete message is obtained, the electronic device may cut according to the agreed cutting rules. For example, if the first 20 bytes of the contracted complete message represent a key, then the cut rule includes cutting the first 20 bytes of the message as the first message primary key (first key) and the remaining portion as the first message (first data).
Step S103: and receiving at least one second data packet returned by the server side server, and obtaining second matching parameters corresponding to each second data packet, wherein the second data packet is data responding to the data request, and the second matching parameters are parameters representing response identification of the data request in the second data packet.
The server sends a second data packet to the electronic device based on the long connection, and the electronic device parses the second data packet to obtain a second matching parameter. For example, the 7 th, 11 th and 41 st values in the parsed values of the second data packet are the report Wen Zhujian, and the three values are spliced together to form the second report Wen Zhujian (the second key).
Step S104: and sending each second data packet to a corresponding client server based on at least one first matching parameter and at least one second matching parameter.
In this embodiment, the electronic device of the third party realizes efficient processing and forwarding of the first data packet and the second data packet by establishing a short connection with the client server and a long connection with the server. Meanwhile, through the first matching parameters and the second matching parameters, the electronic equipment can accurately forward the second data packets from different server-side servers to the corresponding client-side servers, ensure the synchronism of the data, realize the purpose of converting the communication mode of the client-side servers from asynchronous to synchronous, improve the communication efficiency, reduce the waste of communication resources and reduce the complexity of a communication system.
The electronic equipment of the third party realizes complete isolation of the data packet sending and receiving processes by establishing short connection with the client server and long connection with the server, and the data packet sending and receiving processes are not affected by each other. The electronic equipment receives the first data packet of the external data request and then completes the sending, matches the second data packet after receiving the returned second data packet, and accurately sends each second data packet to the matched client server, so that the operation processing capacity of the client server is reduced, and the processing speed of the whole communication process is improved.
In this embodiment, after step S101, the following processing is further included for each client server: for each client server, checking the correctness of the first message primary key and the first message; and if the primary key of the first message and the first message pass the verification, executing the step S102.
The correctness checking comprises checking the first message main key and checking the first message, wherein the checking on the first message main key can be the length checking of the message main key, the checking on the first message comprises blank checking and the length checking of the first message, and the correctness checking is carried out on the first message main key and the first message, so that the length of the parameter can be ensured to be within a specified range, and the integrity and the validity of the first data packet can be ensured.
In this embodiment, after step S102, the following processing is further included: and for each client server, calling a public buffer memory to perform blocking waiting corresponding to the client server, wherein the blocking waiting comprises a key value, and the key value is the primary key of the first message.
In this embodiment, the electronic device includes a unified cache server cluster, where the cache server cluster is configured to provide a public cache for blocking waiting, and the blocking waiting is configured to perform matching waiting of a corresponding client server, and the cache server cluster may be a dis cluster, for example.
In this embodiment, the method brpop (final int timeout, FINAL STRING KEY) of JedisCluste may be used to implement blocking wait, jedisCluster is a client library in Java for interacting with the dis cluster. In Redis cluster brpop is a list-related blocking pop primitive.
And analyzing the second data packet to obtain a second matching parameter and a value of the message, wherein the value is the message returned by the server side server, and the second matching parameter comprises a second message primary key.
Illustratively, the 7 th, 11 th and 41 st values are spliced to form a message primary key by analyzing the message, the message primary key is used as a second message Wen Zhujian (second key), and the analyzed complete message is used as a value of the message.
After step S103, the method further includes the following steps: and for each second data packet, storing a second message primary key corresponding to the second data packet into the public cache.
In this embodiment, after the second message primary key and the value are obtained by parsing, the second message primary key and the value are respectively put into the public cache.
The step S104 specifically includes the following processes: and for each second data packet, acquiring a first message primary key consistent with a second message primary key corresponding to the second data packet in the public cache, taking a client server corresponding to the first message primary key as a server matched with the second data packet, ending blocking waiting corresponding to the client server, and sending the second data packet to the client server.
When the related second message main key is put into the public buffer, the thread waiting for blocking can be matched with the second message main key, when the second message main key is matched with the first message main key corresponding to the blocking waiting, the value corresponding to the second message main key is obtained, the value is sent to the client server corresponding to the blocking waiting, and meanwhile, the blocking waiting is finished in the public buffer and related data are deleted. And according to the consistency matching condition of the second message main key and the first message main key, the matching of the client server and the returned second data packet is completed, and the correctness matching of the second data packet of the asynchronous simplex long connection is realized.
In this embodiment, the blocking waiting implemented by using the brpop (final int timeout, FINAL STRING KEY) method of JedisCluste includes a timeout mechanism, and the blocking waiting further includes a waiting timeout time, and the corresponding waiting timeout time can be set according to different service requirements.
After step S102, the following processing is further included: for each client server, judging whether the waiting time of the blocking waiting exceeds the waiting timeout time; and if the waiting timeout time is exceeded, sending timeout prompt information to the client server.
The electronic equipment acquires the waiting time of blocking waiting in real time, compares the actual waiting time with the corresponding waiting timeout time, and when the actual waiting time exceeds the corresponding waiting timeout time, the blocking waiting is indicated to be not matched with data in the appointed time, so that the electronic equipment returns prompt information to the corresponding client server, the prompt information can comprise timeout information, and the client can conveniently take relevant processing, so that the possibility of long-term waiting matching of excessive blocking waiting threads is reduced, and the possibility of causing the false death of a processing system corresponding to the electronic equipment is reduced.
In this embodiment, after the client server receives the second data packet or the prompt message returned by the electronic device, the short connection between the client server and the electronic device may be disconnected.
In this embodiment, before step S102, the following processing is further included: for each client server, acquiring the complete length corresponding to the first data packet based on a preset message rule; judging whether the first data packet is complete or not based on the complete length; if so, step S102 is performed.
The message is defined as preset information in the electronic device, for example, the first four bytes of the message corresponding to a certain first data packet are defined as representing the message length, the electronic device can read the first four bytes when reading the message, so that the length of the complete message is obtained, and then the complete message with the fixed length is read according to the length of the complete message, so that the possibility of the occurrence of the sticking phenomenon when sending the message is reduced.
In this embodiment, when the electronic device receives the second data packet returned by the server, whether the second data packet is complete or not may also be verified based on the corresponding packet rule.
In this embodiment, when no data interaction occurs between the electronic device and the server for more than a certain time, the electronic device may send a heartbeat packet at regular time, so as to maintain long connection between the electronic device and the server. The heartbeat packet includes a string of packets agreed by both the electronic device and the server, such as "000000". After step S103, the following processing is further included: judging whether each second data packet is a heartbeat packet or not; if yes, discarding the second data packet; and if not, executing the step of acquiring the second matching parameters corresponding to each second data packet.
The electronic device compares the received second data packet with the heartbeat packet, so as to determine whether the second data packet is the heartbeat packet, and when the packet in the second data packet is "000000", the second data packet is the heartbeat packet and can be directly discarded and not processed, thereby avoiding further processing the heartbeat packet without actual data content, reducing the processing burden of the electronic device, and improving the processing efficiency.
In this embodiment, before step S103, the following processing is further included: for each client server, detecting whether a long connection exists between the client server and the corresponding server; if not, reestablishing the long connection; if so, step S103 is performed.
Before the electronic equipment forwards the first data packet, whether the long connection with the client server is normal or not is detected, so that the first data packet is sent after the long connection is established successfully, and the possibility of communication failure between the electronic equipment and the client server is reduced.
Based on the same technical concept, the present application also provides a real-time communication device, as shown in fig. 2, the real-time communication device 200 mainly includes:
A first receiving and acquiring module 201, configured to, for each client server, receive a first data packet sent by the client server based on a short connection established with the client server, and acquire a first matching parameter corresponding to the first data packet, where the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet;
a forwarding module 202, configured to, for each of the client servers, forward the first data packet to the server corresponding to the client server based on the long connection established with at least one server;
The second receiving and acquiring module 203 is configured to receive a second data packet returned by at least one server side server, and acquire a second matching parameter corresponding to each second data packet, where the second data packet is data responding to the data request, and the second matching parameter is a parameter representing a response identifier of the data request in the second data packet;
And a sending module 204, configured to send each of the second data packets to a corresponding client server based on at least one first matching parameter and at least one second matching parameter.
Optionally, the first matching parameter includes a first message primary key, and the first data packet corresponds to a first message; for each of the client servers, after the first receiving and acquiring module 201, further includes:
The verification module is used for verifying the correctness of the first message primary key and the first message for each client server; if the primary key of the first message and the first message pass verification, the processing of the forwarding module 202 is executed.
Optionally, after the forwarding module 202, the method further includes:
the blocking waiting module is used for calling the public buffer for each client server to carry out blocking waiting corresponding to the client server, wherein the blocking waiting comprises a key value, and the key value is the primary key of the first message;
For each of the second data packets, the second matching parameters include a second report Wen Zhujian, which further includes, after the second receiving and acquiring module 203:
The storage buffer module is used for storing a second message primary key corresponding to each second data packet into the public buffer for each second data packet;
the transmitting module 204 includes:
And the matching sub-module is used for acquiring a first message primary key consistent with a second message primary key corresponding to the second data packet in the public buffer memory for each second data packet, taking a client server corresponding to the first message primary key as a server matched with the second data packet, ending blocking waiting corresponding to the client server, and sending the second data packet to the client server.
Optionally, the blocking waiting further includes a waiting timeout time, and after the forwarding module 202, further includes:
a judging timeout module, configured to judge, for each of the client servers, whether the waiting time of blocking waiting exceeds the waiting timeout time; and if the waiting timeout time is exceeded, sending timeout prompt information to the client server.
Optionally, before the forwarding module 202, the method further includes:
the judging complete module is used for acquiring the complete length corresponding to the first data packet based on a preset message rule for each client server; judging whether the first data packet is complete or not based on the complete length; if so, processing by forwarding module 202 is performed.
Optionally, after the second receiving and acquiring module 203, the method further includes:
The heartbeat packet judging module is used for judging whether each second data packet is a heartbeat packet or not; if yes, discarding the second data packet; and if not, executing the step of acquiring the second matching parameters corresponding to each second data packet.
Optionally, before the forwarding module 202, for each of the client servers, the method further includes:
The detection connection module is used for detecting whether long connection exists between each client server and the corresponding server; if not, the long connection is reestablished.
In one example, a module in any of the above apparatuses may be one or more integrated circuits configured to implement the above methods, for example: one or more application specific integrated circuits (application specific integratedcircuit, ASIC), or one or more digital signal processors (DIGITAL SIGNAL processor, DSP), or one or more field programmable gate arrays (field programmable GATE ARRAY, FPGA), or a combination of at least two of these integrated circuit forms.
For another example, when a module in an apparatus may be implemented in the form of a scheduler of processing elements, the processing elements may be general-purpose processors, such as a central processing unit (central processing unit, CPU) or other processor that may invoke a program. For another example, the modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
Various objects such as various messages/information/devices/network elements/systems/devices/actions/operations/processes/concepts may be named in the present application, and it should be understood that these specific names do not constitute limitations on related objects, and that the named names may be changed according to the scenario, context, or usage habit, etc., and understanding of technical meaning of technical terms in the present application should be mainly determined from functions and technical effects that are embodied/performed in the technical solution.
It will be clearly understood by those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system, apparatus and module may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
Those of ordinary skill in the art will appreciate that the various illustrative modules and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
Based on the same technical idea, the present application further provides an electronic device, as shown in fig. 3, where the electronic device 300 includes a processor 301 and a memory 302, and may further include an information input/information output (I/O) interface 303, one or more of communication components 304, and a communication bus 305.
Wherein the processor 301 is configured to control the overall operation of the electronic device 300 to perform all or part of the steps in the real-time communication method described above; the memory 302 is used to store various types of data to support operation at the electronic device 300, which may include, for example, instructions for any application or method operating on the electronic device 300, as well as application-related data. The Memory 302 may be implemented by any type or combination of volatile or non-volatile Memory devices, such as one or more of static random access Memory (Static Random Access Memory, SRAM), electrically erasable programmable Read-Only Memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ-Only Memory, EEPROM), erasable programmable Read-Only Memory (Erasable Programmable Read-Only Memory, EPROM), programmable Read-Only Memory (Programmable Read-Only Memory, PROM), read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk, or optical disk.
The I/O interface 303 provides an interface between the processor 301 and other interface modules, which may be a keyboard, mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 304 is used to test wired or wireless communication between the electronic device 300 and other devices. Wireless communication, such as Wi-Fi, bluetooth, near field communication (NEARFIELD COMMUNICATION, NFC for short), 2G, 3G, or 4G, or a combination of one or more thereof, the corresponding communication component 304 may thus comprise: wi-Fi part, bluetooth part, NFC part.
Communication bus 305 may include a pathway to transfer information between the aforementioned components. The communication bus 305 may be a PCI (PERIPHERAL COMPONENT INTERCONNECT, peripheral component interconnect standard) bus or an EISA (Extended Industry Standard Architecture ) bus, or the like. The communication bus 305 may be divided into an address bus, a data bus, a control bus, and the like.
The electronic device 300 may be implemented by one or more application specific integrated circuits (Application SpecificIntegrated Circuit, ASIC), digital signal Processor (DIGITAL SIGNAL Processor, DSP), digital signal processing device (DIGITAL SIGNAL Processing Device, DSPD), programmable logic device (Programmable Logic Device, PLD), field programmable gate array (Field Programmable GATE ARRAY, FPGA), controller, microcontroller, microprocessor, or other electronic components for performing the real-time communication methods as described in the above embodiments.
The electronic device 300 may include, but is not limited to, a mobile terminal such as a digital broadcast receiver, a PDA (personal digital assistant), a PMP (portable multimedia player), etc., and a fixed terminal such as a digital TV, a desktop computer, etc., and may also be a server, etc.
Based on the same technical concept, the application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program realizes the steps of the real-time communication method when being executed by a processor.
The computer readable storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present invention, the meaning of "plurality" means at least two, for example, two, three, etc., unless specifically defined otherwise.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
While embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the invention, and that variations, modifications, alternatives and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the invention.
Claims (10)
1. A method of real-time communication, comprising:
For each client server, receiving a first data packet sent by the client server based on a short connection established with the client server, and acquiring a first matching parameter corresponding to the first data packet, wherein the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet;
forwarding, for each of the client servers, the first data packet to the server corresponding to the client server based on the long connection established with at least one server;
receiving at least one second data packet returned by the server, and obtaining second matching parameters corresponding to each second data packet, wherein the second data packet is data responding to the data request, and the second matching parameters are parameters representing response identification of the data request in the second data packet;
And sending each second data packet to a corresponding client server based on at least one first matching parameter and at least one second matching parameter.
2. The method according to claim 1, wherein the first matching parameter includes a first message key, and the first data packet corresponds to a first message; for each client server, after the obtaining the first matching parameter corresponding to the first data packet, the method further includes:
for each client server, checking the correctness of the first message primary key and the first message;
And if the primary key of the first message and the first message pass verification, executing the step of forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server.
3. The method according to claim 2, further comprising, after said forwarding said first data packet to said server corresponding to said client server:
for each client server, calling a public cache to perform blocking waiting corresponding to the client server, wherein the blocking waiting comprises a key value, and the key value is the primary key of the first message;
for each second data packet, the second matching parameters include a second report Wen Zhujian, and after the second matching parameters corresponding to each second data packet are obtained, the method further includes:
For each second data packet, storing a second message primary key corresponding to the second data packet into the public cache;
The sending each second data packet to the corresponding client server based on at least one first matching parameter and at least one second matching parameter includes:
And for each second data packet, acquiring a first message primary key consistent with a second message primary key corresponding to the second data packet in the public cache, taking a client server corresponding to the first message primary key as a server matched with the second data packet, ending blocking waiting corresponding to the client server, and sending the second data packet to the client server.
4. A method of real-time communication according to claim 3, wherein said blocking waiting further comprises waiting for a timeout, after said forwarding said first data packet to said server corresponding to said client server, further comprising:
For each client server, judging whether the waiting time of the blocking waiting exceeds the waiting timeout time; and if the waiting timeout time is exceeded, sending timeout prompt information to the client server.
5. The method according to claim 1, further comprising, before forwarding the first data packet to the server corresponding to the client server based on the long connection established with the at least one server:
For each client server, acquiring the complete length corresponding to the first data packet based on a preset message rule; judging whether the first data packet is complete or not based on the complete length; and if so, executing the step of forwarding the first data packet to the server corresponding to the client server based on the long connection established with at least one server.
6. The method according to claim 1, further comprising, after said receiving the second data packet returned from the at least one server, the steps of:
Judging whether each second data packet is a heartbeat packet or not; if yes, discarding the second data packet; and if not, executing the step of acquiring the second matching parameters corresponding to each second data packet.
7. The method according to claim 1, wherein for each of the client servers, before forwarding the first data packet to the server corresponding to the client server based on the long connection established with the at least one server, the method further comprises:
For each client server, detecting whether a long connection exists between the client server and the corresponding server; if not, the long connection is reestablished.
8. A real-time communication device, comprising:
The first receiving and acquiring module is used for receiving a first data packet sent by the client server based on the short connection established with the client server for each client server, and acquiring a first matching parameter corresponding to the first data packet, wherein the first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing a data request identifier in the first data packet;
The forwarding module is used for forwarding the first data packet to the server corresponding to the client server based on the long connection established between the client server and at least one server;
The second receiving and acquiring module is used for receiving at least one second data packet returned by the server side server, acquiring second matching parameters corresponding to each second data packet, wherein the second data packet is data responding to the data request, and the second matching parameters are parameters representing response identification of the data request in the second data packet;
and the sending module is used for sending each second data packet to the corresponding client server based on at least one first matching parameter and at least one second matching parameter.
9. An electronic device comprising a processor and a memory, the processor coupled to the memory;
The processor is configured to execute a computer program stored in the memory to cause the electronic device to perform the method of any one of claims 1 to 7.
10. A computer readable storage medium comprising a computer program or instructions which, when run on a computer, cause the computer to perform the method of any of claims 1 to 7.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410357705.2A CN118301133B (en) | 2024-03-27 | 2024-03-27 | Real-time communication method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410357705.2A CN118301133B (en) | 2024-03-27 | 2024-03-27 | Real-time communication method, device, equipment and readable storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN118301133A true CN118301133A (en) | 2024-07-05 |
| CN118301133B CN118301133B (en) | 2025-07-22 |
Family
ID=91685315
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410357705.2A Active CN118301133B (en) | 2024-03-27 | 2024-03-27 | Real-time communication method, device, equipment and readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118301133B (en) |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20080195706A1 (en) * | 2005-06-09 | 2008-08-14 | Tencent Technology (Shenzhen) Company Ltd. | Group Based Communication Method, System and Client |
| CN102739560A (en) * | 2011-04-13 | 2012-10-17 | 腾讯科技(深圳)有限公司 | Instant communication method, system thereof and device thereof |
| WO2015096149A1 (en) * | 2013-12-27 | 2015-07-02 | 华为技术有限公司 | Tcp link configuration method, apparatus and device |
| CN107529229A (en) * | 2016-06-21 | 2017-12-29 | 中兴通讯股份有限公司 | The method of data transfer, apparatus and system |
| CN109660584A (en) * | 2017-10-12 | 2019-04-19 | 阿里巴巴集团控股有限公司 | A kind of method and communication means and communication system of client and the long connection of server foundation |
| CN115914335A (en) * | 2022-12-07 | 2023-04-04 | 中国平安财产保险股份有限公司 | Long connection creation method, device, computer equipment and storage medium |
| CN115967709A (en) * | 2022-12-28 | 2023-04-14 | 深圳创维新世界科技有限公司 | Request result synchronous returning method, device, terminal equipment and storage medium |
-
2024
- 2024-03-27 CN CN202410357705.2A patent/CN118301133B/en active Active
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20080195706A1 (en) * | 2005-06-09 | 2008-08-14 | Tencent Technology (Shenzhen) Company Ltd. | Group Based Communication Method, System and Client |
| CN102739560A (en) * | 2011-04-13 | 2012-10-17 | 腾讯科技(深圳)有限公司 | Instant communication method, system thereof and device thereof |
| WO2015096149A1 (en) * | 2013-12-27 | 2015-07-02 | 华为技术有限公司 | Tcp link configuration method, apparatus and device |
| CN107529229A (en) * | 2016-06-21 | 2017-12-29 | 中兴通讯股份有限公司 | The method of data transfer, apparatus and system |
| CN109660584A (en) * | 2017-10-12 | 2019-04-19 | 阿里巴巴集团控股有限公司 | A kind of method and communication means and communication system of client and the long connection of server foundation |
| CN115914335A (en) * | 2022-12-07 | 2023-04-04 | 中国平安财产保险股份有限公司 | Long connection creation method, device, computer equipment and storage medium |
| CN115967709A (en) * | 2022-12-28 | 2023-04-14 | 深圳创维新世界科技有限公司 | Request result synchronous returning method, device, terminal equipment and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN118301133B (en) | 2025-07-22 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN114124451B (en) | A data processing method, system and computer storage medium of an Internet of Things device | |
| CN112788128B (en) | Business information pushing method and device, storage medium and electronic device | |
| CN112261094B (en) | Message processing method and proxy server | |
| CN113259479B (en) | Data processing method and equipment | |
| CN111666745A (en) | File downloading method, device, server and medium | |
| CN114338650B (en) | File transmission method, device, electronic equipment and readable storage medium | |
| CN111935017B (en) | Cross-network application calling method and device and routing equipment | |
| CN106453136A (en) | Method and device for establishing message queue | |
| CN113360301A (en) | Message transmission system and method | |
| CN110311855B (en) | User message processing method and device, electronic equipment and storage medium | |
| CN113965628A (en) | Message scheduling method, server and storage medium | |
| WO2024103943A1 (en) | Service processing method and apparatus, storage medium, and device | |
| CN114244758B (en) | Network diagnosis method, storage medium, electronic equipment and system of android platform | |
| CN111913817A (en) | Data transmission method, system and equipment and computer readable storage medium | |
| CN118301133B (en) | Real-time communication method, device, equipment and readable storage medium | |
| CN119105887B (en) | Message processing method, device, electronic device and storage medium | |
| CN112131014B (en) | Decision engine system and business processing method thereof | |
| CN111752728B (en) | Message transmission method and device | |
| WO2025201428A1 (en) | Message transmission method, apparatus and system, storage medium, electronic device, and product | |
| CN111416852A (en) | Method for session synchronization among multiple load balancers and load balancer | |
| CN115051866B (en) | A message processing method and device, storage medium and electronic equipment | |
| CN111416851A (en) | Method for session synchronization among multiple load balancers and load balancer | |
| CN113794620B (en) | Message sending method, device, equipment, system and storage medium | |
| CN116366700A (en) | A command transmission method, device, equipment and medium | |
| CN114328081A (en) | Storage node performance data transmission method, device, equipment and medium |
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 |