A Real-Time Communication Method, Device, Equipment and Readable Storage Medium
By establishing short and long connections between the client and the server, using matching parameters and public cache, the resource waste and complexity problems in asynchronous single foreman connections are solved, and efficient synchronous data transmission is achieved.
Patent Information
- Application Number
- CN202410357705.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-27
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2044-03-27
AI Technical Summary
In the asynchronous single-foreman connection communication between the client and the server, there are problems of waste of communication resources and complexity, resulting in inefficient communication.
By establishing short and long connections between the client and the server, the accurate forwarding and synchronization of packets is achieved using matching parameters, including correctness verification, blocking waiting and the use of public caches, to ensure the integrity and synchronization of packets.
It improves communication efficiency, reduces the waste of communication resources and system complexity, and realizes synchronous communication between the client and the server.
Smart Images

Figure CN118301133B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular, to a real-time communication method, apparatus, device, and readable storage medium. Background Art
[0002] With the rapid development of information technology and the continuous expansion of enterprise services, the communication requirements between the client and the server have increased day by day, and the communication methods have also shown a diversified trend. In practical applications, the client is a device that sends data requests, and the server is a device that provides services corresponding to the data requests. The client and the server usually communicate in an asynchronous single-worker long connection manner. The asynchronous single-worker long connection needs to separate the reception processing and the transmission processing during the communication process, that is, both the client and the server need to use a receiver for receiving data and a transmitter for transmitting data.
[0003] In the asynchronous single-worker long connection communication, the division of labor between the transmitter and the receiver in the communication devices of both parties is clear, and the data can only be unidirectionally transmitted from the transmitter to the receiver corresponding to another device. In scenarios where the number of clients is large, the requests are frequent, and the connection duration is short, the asynchronous single-worker long connection between the client and the server will cause waste of communication resources, increase the complexity of communication between the client and the server, and reduce the communication efficiency between the client and the server. Summary of the Invention
[0004] In order to reduce the waste of communication resources, reduce the complexity of the communication system, and improve the communication efficiency, the present application provides a real-time communication method, apparatus, device, and readable storage medium.
[0005] In a first aspect, the present application provides a real-time communication method, including:
[0006] For each of the client servers, based on the short connection established with the client server, receive a first data packet sent by the client server, and obtain a first matching parameter corresponding to the first data packet. 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;
[0007] For each of the client servers, based on the long connection established with at least one server, forward the first data packet to the server corresponding to the client server;
[0008] Receive second data packets returned by at least one of the servers, and obtain second matching parameters corresponding to the second data packets. The second data packets are data in response to the data request, and the second matching parameters are parameters representing response identifiers for the data request in the second data packets;
[0009] Based on at least one first matching parameter and at least one second matching parameter, send each of the second data packets to the corresponding client server.
[0010] The beneficial effects of the present invention are as follows: By establishing a short connection with the client server and a long connection with the server, the processing and forwarding of the first data packet and the second data packet are realized. Through the first matching parameter and the second matching parameter, the electronic device can accurately forward the second data packets from different server servers to the corresponding client servers, ensure data synchronization, achieve the purpose of changing the communication mode of the client server from asynchronous to synchronous, improve communication efficiency, reduce waste of communication resources, and reduce the complexity of the communication system.
[0011] Further, 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 obtaining the first matching parameter corresponding to the first data packet, it further includes:
[0012] For each of the client servers, perform a correctness check on the first message primary key and the first message;
[0013] If both the first message primary key and the first message pass the check, then execute 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.
[0014] The beneficial effect of adopting the above further solution is: By performing a correctness check on the first message primary key and the first message, it can be ensured that the check items corresponding to the first data packet meet the corresponding regulations, and the integrity and validity of the first data packet are ensured.
[0015] Further, after forwarding the first data packet to the server corresponding to the client server, it further includes:
[0016] For each of the client servers, call the public cache to perform a blocking wait corresponding to the client server, and the blocking wait includes a key value, and the key value is the first message primary key;
[0017] For each of the second data packets, the second matching parameter includes a second message primary key. After obtaining the second matching parameter corresponding to each of the second data packets, it further includes:
[0018] For each of the second data packets, store the second message primary key corresponding to the second data packet into the public cache;
[0019] Sending each of the second data packets to the corresponding client server based on at least one first matching parameter and at least one second matching parameter includes:
[0020] For each of the second data packets, obtain the first message primary key in the public cache that is consistent with the second message primary key corresponding to this second data packet, use the client server corresponding to this first message primary key as the server matched by the second data packet, and end the blocked waiting corresponding to this client server, and send the second data packet to this client server.
[0021] The beneficial effect of adopting the above further solution is that the public cache supports concurrent access and parallel processing. Multiple second message primary keys and multiple first message primary keys can be matched simultaneously in the public cache, improving the matching speed. According to the matching situation of the second message primary key and the first message primary key, the matching of the client server and the returned second data packet is completed, realizing the correct matching of the second data packet of the asynchronous single-worker long connection.
[0022] Further, the blocked waiting further includes a waiting timeout. After forwarding the first data packet to the server corresponding to this client server, it further includes:
[0023] For each of the client servers, determine whether the waiting time of the blocked waiting exceeds the waiting timeout; if it exceeds the waiting timeout, send a timeout prompt message to this client server.
[0024] The beneficial effect of adopting the above further solution is that it is convenient for the client to take relevant processing, thereby reducing the possibility of excessive blocked waiting threads waiting for matching for a long time and reducing the possibility of causing the processing system corresponding to the electronic device to become unresponsive.
[0025] Further, before forwarding the first data packet to the server corresponding to this client server based on the long connection established with at least one server, it further includes:
[0026] For each of the client servers, obtain the complete length corresponding to the first data packet based on a preset message regulation; based on the complete length, determine whether the first data packet is complete; if it is complete, execute the step of forwarding the first data packet to the server corresponding to this client server based on the long connection established with at least one server.
[0027] The beneficial effect of adopting the above further solution is that it reduces the possibility of packet adhesion when sending messages.
[0028] Further, after receiving at least one second data packet returned by the server, the following steps are also included:
[0029] For each of the second data packets, determine whether the second data packet is a heartbeat message packet; if so, discard the second data packet; if not, perform the step of obtaining second matching parameters corresponding to each of the second data packets.
[0030] The beneficial effect of adopting the above further solution is that by directly discarding and not processing the heartbeat message packet, it avoids further processing of the heartbeat message packet without actual data content, reduces the processing burden of the electronic device, and improves the processing efficiency.
[0031] 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 following steps are also included:
[0032] For each of the client servers, detect whether the long connection with the corresponding server exists; if not, re - establish the long connection.
[0033] The beneficial effect of adopting the above further solution is that by detecting whether the long connection with the client server is normal, the first data packet is sent after the long connection is successfully established, reducing the possibility of communication failure between the electronic device and the client server.
[0034] In a second aspect, the present application provides a real - time communication device, including:
[0035] A first receiving and obtaining module, configured to, for each of the client servers, based on the short connection established with the client server, receive the first data packet sent by the client server and obtain the 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 the data request identifier in the first data packet;
[0036] A forwarding module, configured to, for each of the client servers, based on the long connection established with at least one server, forward the first data packet to the server corresponding to the client server;
[0037] A second receiving and obtaining module, configured to receive at least one second data packet returned by the server and obtain second matching parameters corresponding to each of the second data packets, where the second data packet is data in response to the data request, and the second matching parameter is a parameter representing the response identifier to the data request in the second data packet;
[0038] A sending module, 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.
[0039] In a third aspect, the present application provides an electronic device, including a processor and a memory, the processor being coupled to the memory;
[0040] The processor is configured to execute a computer program stored in the memory, so that the electronic device executes the method according to any one of the first aspects.
[0041] In a fourth aspect, the present application provides a computer-readable storage medium, including a computer program or instruction, when the computer program or instruction runs on a computer, the computer is caused to execute the method according to any one of the first aspects. Description of the Drawings
[0042] Figure 1 is a schematic flowchart of the real-time communication method according to an embodiment of the present application;
[0043] Figure 2 is a structural block diagram of the real-time communication device according to an embodiment of the present application;
[0044] Figure 3 is a structural block diagram of the electronic device according to an embodiment of the present application. Detailed Embodiments
[0045] The following further describes the present application in detail with reference to the drawings.
[0046] An embodiment of the present application provides a real-time communication method, which can be executed by a device. The device can be a server or a terminal device. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smart phone, a tablet computer, a desktop computer, etc., but is not limited thereto.
[0047] As Figure 1 shown, a real-time communication method, with an electronic device as the execution subject, the main process of the method is described as follows (steps S101 to S104):
[0048] Step S101: For each of the client servers, based on the short connection established with the client server, receive a first data packet sent by the client server, and obtain a first matching parameter corresponding to the first data packet. 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.
[0049] Step S102: For each of the client servers, forward the first data packet to the corresponding server server based on the long connection established with at least one server server.
[0050] In this embodiment, the client server is a device that calls an electronic device and sends a data request, and the server server is a target server that interacts with the client server and provides a service corresponding to the data request for the client server. The data request is a request that requires the client server to provide relevant data. Exemplarily, the server server can be a UnionPay server, and the data request corresponding to the client server can be to call the UnionPay server to query the consumption record.
[0051] The electronic device supports both short connections and long connections at the same time. A short connection is a network communication method, and its main feature is that after each data interaction is completed, the communication parties will disconnect the connection. Compared with a long connection, a short connection does not maintain a persistent connection state and is suitable for scenarios where data interaction is not frequent. In a short connection, since the connection is temporary, some unnecessary resource occupations can be reduced, and the system corresponding to the client server can be made simpler and easier to use. In this embodiment, the electronic device can support multiple conventional short connections such as http and socket at the same time.
[0052] A long connection is a network communication method different from a short connection. After the electronic device establishes a long connection with the server server, if there is no data packet to send, both parties also need to maintain the connection. A long connection is suitable for frequent operations and point-to-point communication. In this embodiment, the long connection between the electronic device and the server server can specifically be an asynchronous single-worker long connection. In an asynchronous single-worker long connection, receiving and sending are completed by two different programs. The characteristic of simplex communication is that the transmitter and receiver in the communication parties' devices have clear divisions of labor and can only transmit data in a single fixed direction from the transmitter to the receiver.
[0053] In this embodiment, the electronic device stores a configuration file for establishing connections with the client server and the server server. The configuration file includes the short connection port, the local long connection port, and the address and port corresponding to the server server. There can be multiple server servers.
[0054] When the electronic device starts up, it reads the configuration file and can obtain the address and port corresponding to the server server. The electronic device establishes a long connection according to the address and port corresponding to the server server. Exemplarily, the address configuration scheme for the asynchronous single-worker long connection includes four long connection schemes of A-A1, B-B1, C-C1, and D-D1. When the electronic device starts up, it will obtain the local address corresponding to the electronic device. When it is determined that the local address is A, a long connection from the electronic device A to the server server A1 is established.
[0055] 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 the short connection port corresponding to the electronic device, and establish a short connection between the electronic device and the client server according to the short connection request.
[0056] Exemplarily, the configuration file further includes a first correspondence between the short connection port and the local long connection port, and a second correspondence between the local long connection port and the port corresponding to the server-side server. After the electronic device is started, a long connection can be established between the local long connection port and the port corresponding to the server-side server according to the local long connection port and the second correspondence. The client server can select the short connection port in the electronic device for establishing a short connection according to the data request. The electronic device obtains the corresponding local long connection port according to the first correspondence and the short connection port, so as to obtain the server-side server corresponding to the client server through the local long connection port.
[0057] 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 message (first data) can be directly obtained from the request body corresponding to the HTTP short connection. The request body is the part in the HTTP short connection used to carry the data sent to the electronic device. The client server will send 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.
[0058] If the short connection between the electronic device and the client server is a socket short connection, the electronic device can first obtain the message header of the data sent by the client server, then parse 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 can perform cutting according to the agreed cutting rules. For example, if it is agreed that the first 20 bytes of the complete message represent the key, the cutting rule includes cutting the first 20 bytes of the message as the first message primary key (first key), and the remaining part as the first message (first data).
[0059] Step S103: Receive at least one second data packet returned by the server-side server, and obtain a second matching parameter corresponding to each second data packet. The second data packet is data in response to the data request, and the second matching parameter is a parameter characterizing the response identifier of the data request in the second data packet.
[0060] The server-based server sends a second data packet to the electronic device via a long connection. The electronic device parses the second data packet to obtain a second matching parameter. In this embodiment, the second matching parameter includes a second message primary key. Exemplarily, among the values parsed from the second data packet, the 7th, 11th, and 41st values are the message primary keys. Concatenating these three values can form the second message primary key (second key).
[0061] Step S104: Based on at least one first matching parameter and at least one second matching parameter, send each of the second data packets to the corresponding client server.
[0062] In this embodiment, the third-party electronic device realizes the 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-based server. At the same time, through the first matching parameter and the second matching parameter, the electronic device can accurately forward the second data packets from different server-based servers to the corresponding client servers, ensure data synchronization, achieve the purpose of converting the communication mode of the client server from asynchronous to synchronous, improve communication efficiency, reduce waste of communication resources, and reduce the complexity of the communication system.
[0063] By establishing a short connection with the client server and a long connection with the server-based server, the third-party electronic device realizes a complete isolation between the data packet sending and receiving processes, without affecting each other. After receiving the first data packet of an external data request, the electronic device completes the sending. After receiving the returned second data packet, it performs matching and accurately sends each second data packet to the matched client server, reducing the computing and processing volume of the client server and improving the processing speed of the overall communication process.
[0064] In this embodiment, for each client server, after step S101, the following processing is further included: for each of the client servers, perform a correctness check on the first message primary key and the first message; if both the first message primary key and the first message pass the check, then execute step S102.
[0065] The correctness check includes the check of the first message primary key and the check of the first message. Among them, the check of the first message primary key can be the length check of the message primary key, and the check of the first message includes the null check and the length check of the first message. By performing the correctness check on the first message primary key and the first message, it can ensure that the length of the parameter is within the specified range and ensure the integrity and validity of the first data packet.
[0066] In this embodiment, after step S102, the following processing is further included: for each of the client servers, a common cache is called to perform blocking waiting corresponding to the client server, and the blocking waiting includes a key value, which is the primary key of the first message.
[0067] In this embodiment, the electronic device includes a unified cache server cluster, and the cache server cluster is used to provide the common cache for blocking waiting. The blocking waiting is used to perform matching waiting for the corresponding client server. Exemplarily, the cache server cluster can be a Redis cluster.
[0068] In this embodiment, the brpop(final int timeout, final String key) method of JedisCluste can be used to implement blocking waiting. JedisCluster is a client library in Java for interacting with the Redis cluster. In the Redis cluster, brpop is a blocking pop primitive related to a list.
[0069] For each of the second data packets, by parsing the second data packet, a second matching parameter and the value of the message are obtained. The value is the message returned by the server, and the second matching parameter includes the primary key of the second message.
[0070] Exemplarily, by parsing the message, the 7th, 11th, and 41st values parsed out are concatenated to form the primary key of the message, and this primary key of the message is used as the primary key of the second message (the second key), and the parsed complete message is used as the value of the message.
[0071] After step S103, the following processing is further included: for each of the second data packets, the primary key of the second message corresponding to the second data packet is stored in the common cache.
[0072] In this embodiment, after parsing out the primary key of the second message and the value, the primary key of the second message and the value are respectively put into the common cache.
[0073] Step S104 specifically includes the following processing: for each of the second data packets, the primary key of the first message that is consistent with the primary key of the second message corresponding to the second data packet in the common cache is obtained, the client server corresponding to this primary key of the first message is used as the server matched by the second data packet, and the blocking waiting corresponding to the client server is ended, and the second data packet is sent to the client server.
[0074] When the relevant second message primary key is put into the public cache, the blocked waiting thread can match with the second message primary key. When the second message primary key matches the first message primary key corresponding to the blocked waiting, obtain the value corresponding to the second message primary key, send the value to the client server corresponding to the blocked waiting, and at the same time end the blocked waiting in the public cache and delete the relevant data. According to the consistency matching situation between the second message primary key and the first message primary key, the matching of the client server and the returned second data packet is completed, realizing the correct matching of the second data packet of the asynchronous single-worker long connection.
[0075] In this embodiment, the blocked waiting implemented by using the brpop(final int timeout, final String key) method of JedisCluste includes a timeout mechanism. The blocked waiting also includes a waiting timeout time, and the corresponding waiting timeout time can be set according to different service requirements.
[0076] After step S102, the following processing is also included: for each of the client servers, determine whether the waiting time of the blocked waiting exceeds the waiting timeout time; if it exceeds the waiting timeout time, send a timeout prompt message to the client server.
[0077] The electronic device obtains the waiting time of the blocked waiting in real time, compares the actual waiting time with the corresponding waiting timeout time. When the actual waiting time exceeds the corresponding waiting timeout time, it means that the blocked waiting does not match the data within the specified time. Therefore, the electronic device returns a prompt message to the corresponding client server. The prompt message can include timeout information, which is convenient for the client to take relevant processing, thereby reducing the possibility of too many blocked waiting threads waiting for matching for a long time and reducing the possibility of causing the corresponding processing system of the electronic device to become unresponsive.
[0078] 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 can be disconnected.
[0079] In this embodiment, before step S102, the following processing is also included: for each of the client servers, obtain the complete length corresponding to the first data packet based on a preset message regulation; based on the complete length, determine whether the first data packet is complete; if it is complete, execute step S102.
[0080] The message is defined as preset information in the electronic device. For example, the message corresponding to a first data packet is defined such that the first four bytes of the message represent the message length. When the electronic device reads the message, it can first read the first four bytes to obtain the length of the complete message, and then read the complete message of a fixed length according to the length of the complete message, thereby reducing the possibility of packet sticking when sending the message.
[0081] In this embodiment, when the electronic device receives the second data packet returned by the server of the server, it can also verify whether the second data packet is complete based on the corresponding message specification.
[0082] In this embodiment, when there is no data interaction between the electronic device and the server of the server for more than a certain period of time, the electronic device will periodically send a heartbeat message packet to maintain the long connection between the electronic device and the server of the server. The heartbeat message packet includes a string of messages agreed upon by both the electronic device and the server of the server, such as "000000". After step S103, the following processing is further included: for each of the second data packets, determine whether the second data packet is a heartbeat message packet; if so, discard the second data packet; if not, perform the step of obtaining the second matching parameter corresponding to each of the second data packets.
[0083] The electronic device compares the received second data packet with the heartbeat message packet to determine whether the second data packet is a heartbeat message packet. Exemplarily, when the message in the second data packet is "000000", the second data packet is a heartbeat message packet and can be directly discarded without further processing, thereby avoiding further processing of the heartbeat message packet without actual data content, reducing the processing burden of the electronic device, and improving the processing efficiency.
[0084] In this embodiment, before step S103, the following processing is further included: for each of the client servers, detect whether the long connection with the corresponding server of the server exists; if not, re - establish the long connection; if it exists, perform step S103.
[0085] Before the electronic device forwards the first data packet, by detecting whether the long connection with the client server is normal, the first data packet is sent after the long connection is successfully established, reducing the possibility of communication failure between the electronic device and the client server.
[0086] Based on the same technical concept, the present application also provides a real - time communication device, as Figure 2 shown. The real - time communication device 200 mainly includes:
[0087] The first receiving and obtaining module 201 is configured to, for each of the client servers, based on the short connection established with the client server, receive the first data packet sent by the client server and obtain the first matching parameter corresponding to the first data packet. The first data packet is a parameter characterizing a data request, and the first matching parameter is a parameter characterizing the data request identifier in the first data packet.
[0088] The forwarding module 202 is configured to, for each of the client servers, based on the long connection established with at least one server, forward the first data packet to the server corresponding to the client server.
[0089] The second receiving and obtaining module 203 is configured to receive the second data packets returned by at least one of the servers and obtain the second matching parameters corresponding to the second data packets. The second data packets are data in response to the data request, and the second matching parameters are parameters characterizing the response identifiers of the data requests in the second data packets.
[0090] The sending module 204 is configured to send each of the second data packets to the corresponding client server based on at least one first matching parameter and at least one second matching parameter.
[0091] 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 obtaining module 201, it further includes:
[0092] The verification module is configured to, for each of the client servers, verify the correctness of the first message primary key and the first message. If both the first message primary key and the first message pass the verification, then execute the processing of the forwarding module 202.
[0093] Optionally, after the forwarding module 202, it further includes:
[0094] The blocking and waiting module is configured to, for each of the client servers, call the common cache to perform blocking and waiting corresponding to the client server. The blocking and waiting includes a key value, and the key value is the first message primary key.
[0095] For each of the second data packets, the second matching parameter includes a second message primary key. After the second receiving and obtaining module 203, it further includes:
[0096] The caching module is configured to, for each of the second data packets, store the second message primary key corresponding to the second data packet in the common cache.
[0097] The sending module 204 includes:
[0098] A matching sub-module, for each of the second data packets, to obtain in the common cache a first message primary key that is the same as the second message primary key corresponding to the second data packet, use the client server corresponding to the first message primary key as the server matched by the second data packet, end the blocked waiting corresponding to the client server, and send the second data packet to the client server.
[0099] Optionally, the blocked waiting further includes a waiting timeout. After the forwarding module 202, it further includes:
[0100] A timeout judgment module, for each of the client servers, to judge whether the waiting time of the blocked waiting exceeds the waiting timeout; if it exceeds the waiting timeout, send a timeout prompt message to the client server.
[0101] Optionally, before the forwarding module 202, it further includes:
[0102] A completeness judgment module, for each of the client servers, to obtain the complete length corresponding to the first data packet based on a preset message regulation; based on the complete length, judge whether the first data packet is complete; if it is complete, perform the processing of the forwarding module 202.
[0103] Optionally, after the second receiving and obtaining module 203, it further includes:
[0104] A heartbeat message packet judgment module, for each of the second data packets, to judge whether the second data packet is a heartbeat message packet; if so, discard the second data packet; if not, perform the step of obtaining the second matching parameters corresponding to each of the second data packets.
[0105] Optionally, for each of the client servers, before the forwarding module 202, it further includes:
[0106] A connection detection module, for each of the client servers, to detect whether the long connection with the corresponding server exists; if not, re-establish the long connection.
[0107] In one example, the modules in any of the above devices may be one or more integrated circuits configured to implement the above methods. For example: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), or a combination of at least two of these integrated circuit forms.
[0108] For another example, when the modules in the device can be implemented in the form of a processing element scheduler, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call programs. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0109] In this application, names may be assigned to various objects such as various messages / information / devices / network elements / systems / devices / actions / operations / processes / concepts, etc. It can be understood that these specific names do not constitute a limitation on the relevant objects, and the assigned names may change with factors such as the scenario, context, or usage habits. The understanding of the technical meaning of the technical terms in this application should be mainly determined from the functions and technical effects reflected / executed in the technical solution.
[0110] Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, devices, and modules described above can refer to the corresponding processes in the foregoing method embodiments and will not be repeated here.
[0111] Those of ordinary skill in the art can realize that the modules and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but this implementation should not be considered to exceed the scope of this application.
[0112] Based on the same technical concept, this application also provides an electronic device, as Figure 3 shown. The electronic device 300 includes a processor 301 and a memory 302, and may further include one or more of an information input / output (I / O) interface 303, a communication component 304, and a communication bus 305.
[0113] Among them, the processor 301 is used to control the overall operation of the electronic device 300 to complete all or part of the steps in the above real-time communication method; the memory 302 is used to store various types of data to support the operation of the electronic device 300. These data 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 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic memory, flash memory, a hard disk, or an optical disc, or one or more of them.
[0114] The I / O interface 303 provides an interface between the processor 301 and other interface modules. The above other interface modules may be a keyboard, a mouse, buttons, etc. These buttons can be virtual buttons or physical buttons. The communication component 304 is used to test the wired or wireless communication between the electronic device 300 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, or 4G, or a combination of one or more of them. Therefore, the corresponding communication component 304 may include: a Wi-Fi component, a Bluetooth component, an NFC component.
[0115] The communication bus 305 may include a path for transmitting information between the above components. The communication bus 305 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 305 can be divided into an address bus, a data bus, a control bus, etc.
[0116] The electronic device 300 can be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components, and is used to execute the real-time communication method given in the above embodiments.
[0117] The electronic device 300 may include, but is not limited to, mobile terminals such as digital broadcast receivers, PDAs (Personal Digital Assistants), PMPs (Portable Multimedia Players), etc., and fixed terminals such as digital TVs, desktop computers, etc., and may also be a server, etc.
[0118] Based on the same technical concept, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above real-time communication method are implemented.
[0119] The computer-readable storage medium may include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs.
[0120] The term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or also includes elements inherent to such process, method, article or device.
[0121] In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0122] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "examples", "specific examples", or "some examples", etc., mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0123] Although the embodiments of the present invention have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present invention.
Claims
1. A real-time communication method, characterized in that, Including: For each client server, based on the short connection established with the client server, receive the first data packet sent by the client server, and obtain the first matching parameter corresponding to the first data packet. The first data packet is a parameter representing a data request, and the first matching parameter is a parameter representing the data request identifier in the first data packet. For each of the client servers, based on the long connection established with at least one server server, forward the first data packet to the server server corresponding to the client server. Receive the second data packets returned by at least one of the server servers, and obtain the second matching parameters corresponding to the respective second data packets. The second data packets are data in response to the data request, and the second matching parameters are parameters representing the response identifiers for the data requests in the second data packets. Based on at least one first matching parameter and at least one second matching parameter, send each of the second data packets to the corresponding client server. 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 obtaining the first matching parameter corresponding to the first data packet, it further includes: For each of the client servers, perform a correctness check on the first message primary key and the first message. If both the first message primary key and the first message pass the check, then execute the step of forwarding the first data packet to the server server corresponding to the client server based on the long connection established with at least one server server. After forwarding the first data packet to the server server corresponding to the client server, it further includes: For each of the client servers, call a common cache to perform a blocking wait corresponding to the client server. The blocking wait includes a key value, and the key value is the first message primary key. For each of the second data packets, the second matching parameter includes a second message primary key. After obtaining the second matching parameters corresponding to the respective second data packets, it further includes: For each of the second data packets, store the second message primary key corresponding to the second data packet in the common cache. The step of sending each of the second data packets to the corresponding client server based on at least one first matching parameter and at least one second matching parameter includes: For each of the second data packets, obtain the first message primary key that is the same as the second message primary key corresponding to the second data packet in the common cache, use the client server corresponding to the first message primary key as the server matched by the second data packet, end the blocking wait corresponding to the client server, and send the second data packet to the client server.
2. The real-time communication method according to claim 1, characterized in that The blocking wait further includes a wait timeout. After forwarding the first data packet to the server server corresponding to the client server, it further includes: For each of the client servers, determine whether the waiting time of the blocked waiting exceeds the waiting timeout; if it exceeds the waiting timeout, send a timeout prompt message to the client server.
3. A real-time communication method according to claim 1, wherein Before forwarding the first data packet to the corresponding server of the client server based on the long connection established with at least one server, it further includes: For each of the client servers, obtain the complete length corresponding to the first data packet based on a preset message rule; based on the complete length, determine whether the first data packet is complete; if it is complete, perform the step of forwarding the first data packet to the corresponding server of the client server based on the long connection established with at least one server.
4. A real-time communication method according to claim 1, characterized in that, After receiving the second data packets returned by at least one of the servers, it further includes: For each of the second data packets, determine whether the second data packet is a heartbeat message packet; if so, discard the second data packet; if not, perform the step of obtaining the second matching parameter corresponding to each of the second data packets.
5. A real-time communication method according to claim 1, characterized in that, For each of the client servers, before forwarding the first data packet to the corresponding server of the client server based on the long connection established with at least one server, it further includes: For each of the client servers, detect whether the long connection with the corresponding server exists; if not, re - establish the long connection.
6. A real-time communication device, characterized in that, It includes: A first receiving and obtaining module, for each client server, based on the short connection established with the client server, receive the first data packet sent by the client server, and obtain the 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 the data request identifier in the first data packet; A forwarding module, for each of the client servers, based on the long connection established with at least one server, forward the first data packet to the corresponding server of the client server; A second receiving and obtaining module, for receiving the second data packets returned by at least one of the servers, and obtaining the second matching parameter corresponding to each of the second data packets, where the second data packet is data in response to the data request, and the second matching parameter is a parameter representing the response identifier of the data request in the second data packet; A sending module, for sending each of the second data packets to the corresponding client server based on at least one first matching parameter and at least one second matching parameter; 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 obtaining module, it further includes: A verification module, for each of the client servers, perform a correctness verification on the first message primary key and the first message; if both the first message primary key and the first message pass the verification, perform the processing of the forwarding module; After the forwarding module, it further includes: A blocking wait module, which is used to, for each of the client servers, call the common cache to perform blocking wait corresponding to the client server, where the blocking wait includes 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 parameter includes a second message primary key. After the second receiving and obtaining module, it further includes: A cache storing module, which is used to, for each of the second data packets, store the second message primary key corresponding to the second data packet into the common cache; The sending module includes: A matching sub-module, which is used to, for each of the second data packets, obtain the primary key of the first message in the common cache that is consistent with the second message primary key corresponding to the second data packet, use the client server corresponding to the primary key of the first message as the server matched by the second data packet, end the blocking wait corresponding to the client server, and send the second data packet to the client server.
7. An electronic device, characterized in that, It includes a processor and a memory, and the processor is coupled to the memory; The processor is used to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, It includes a computer program or instruction. When the computer program or instruction runs on a computer, it causes the computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Data transmission method, device and system
CN107529229A
Request result synchronization return method and device, terminal equipment and storage medium
CN115967709A