Network communication method and system, electronic equipment and medium

By assembling and determining the target communication data in the JavaScript execution environment, combining asynchronous I/O interface and single-threaded polling mechanism, the traditional network communication method has solved the shortcomings in high performance and flexibility, and achieved efficient network communication performance and flexibility.

CN119676151APending Publication Date: 2025-03-21竞技世界(北京)网络技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411859975.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

The traditional network communication method in the JavaScript execution environment based on ChromeV8 has performance bottlenecks in high-performance scenarios and lacks flexibility in handling multi-node access and load balancing.

Method used

By performing data assembly and processing on the target communication data, the target byte stream data is obtained, and the target routing information is determined based on the preset connection initializer, thereby determining the target remote communication node. Then, the target connection identifier is determined from the preset working channel group, and the communication connection is called through the preset asynchronous I/O interface to realize network communication.

Benefits of technology

It realizes improving the performance of network communication on the basis of taking into account performance and flexibility, avoiding multi-threaded switching through asynchronous I/O interface and single-threaded polling mechanism, improving concurrent processing capabilities, and supporting flexible routing policies and connection pool scaling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119676151A_ABST
    Figure CN119676151A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a network communication method and system, electronic equipment and a medium, and the method comprises the steps: carrying out the data assembly processing of target communication data, obtaining target byte stream data, and determining the target routing information corresponding to the target byte stream data based on a preset connection initialization device. And then, according to the target routing information and the target byte stream data, a target connection identifier is determined from a preset working channel group, and the preset working channel group runs based on a single-thread polling mechanism. And finally, calling communication connection between the local and the target remote communication node through a preset asynchronous I / O interface and the target connection identifier, so as to send the target byte stream data to the target remote communication node. Therefore, the network communication performance is improved on the basis of considering the communication flexibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication processing technology, and in particular to a network communication method, system, electronic device and medium. Background Art

[0002] In the traditional JavaScript execution environment based on Chrome V8, the process of network communication is usually based on HttpClient technology or SocketIO technology. Among them, since the former is based on the short connection method of the Http protocol for communication, short connection means that a new connection needs to be established for each communication, which will bring certain performance overhead in high-performance scenarios with frequent requests. Therefore, this type of communication method has certain performance bottlenecks. Correspondingly, although the latter does not have the problem of performance bottlenecks, it lacks flexibility in handling multi-node access and load balancing. The communication connection with each remote node requires additional management and selection, and its communication method has poor flexibility.

[0003] Therefore, how to provide a communication method with both performance and flexibility has become a technical problem that technical personnel in this field urgently need to solve. Summary of the invention

[0004] Based on the above problems, in order to provide a communication method with both performance and flexibility, the embodiments of the present application provide a network communication method, system, electronic device and medium.

[0005] The embodiments of the present application disclose the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a network communication method, including:

[0007] Performing data assembly processing on target communication data to obtain target byte stream data;

[0008] Based on a preset connection initializer, determining target routing information corresponding to the target byte stream data; the target routing information is used to characterize a target remote communication node that needs to perform network communication;

[0009] Determine a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism;

[0010] The communication connection between the local and the target remote communication node is called through the preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

[0011] In a possible implementation, the preset connection initializer includes node communication attribute data corresponding to each of the plurality of remote communication nodes; the target byte stream data includes: a target communication service type;

[0012] The determining, based on a preset connection initializer, target routing information corresponding to the target byte stream data comprises:

[0013] Determining whether the target byte stream data contains the target routing information;

[0014] If the target byte stream data does not contain the target routing information, the target routing information is determined according to the target communication service type and multiple groups of the node communication attribute data.

[0015] In a possible implementation, the preset working channel group includes a plurality of service connection queues, each of which has a corresponding communication service type; the service connection queue includes a plurality of remote communication nodes, and each of which corresponds to a plurality of connection identifiers;

[0016] The step of determining a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data includes:

[0017] Determining a target service connection queue from the plurality of service connection queues according to the target communication service type;

[0018] Determining the target remote communication node from the target service connection queue based on the target routing information;

[0019] According to the preset working channel group, the connection identifier corresponding to the first communication connection is determined as the target connection identifier; the first communication connection is a communication connection that can be currently called by the target remote communication node.

[0020] In a possible implementation, before performing data assembly processing on the target communication data to obtain the target byte stream data, the method further includes:

[0021] Initializing the communication connection based on the plurality of groups of the node communication attribute data and the preset connection initializer to establish a communication connection between the local and each of the remote communication nodes;

[0022] The connection identifiers corresponding to the communication connections between the local and each of the remote communication nodes are stored in the preset working channel group.

[0023] In a possible implementation, the method further includes:

[0024] Periodically sending a heartbeat signal to each of the remote communication nodes through a communication connection between the local and each of the remote communication nodes, so as to periodically obtain a response signal fed back by the remote communication node;

[0025] If the response signal is not received within a preset time period, the corresponding connection identifier is marked as unavailable.

[0026] In a possible implementation, the step of performing data assembly processing on the target communication data to obtain target byte stream data includes:

[0027] The target communication data is subjected to byte stream reordering processing by a data encoder to adjust the byte sequence of the target communication data to obtain the target byte stream data.

[0028] In a second aspect, an embodiment of the present application provides a network communication system, including:

[0029] A data assembly module is used to perform data assembly processing on target communication data to obtain target byte stream data;

[0030] A routing determination module, used to determine target routing information corresponding to the target byte stream data based on a preset connection initializer; the target routing information is used to characterize a target remote communication node that needs to perform network communication;

[0031] An identification determination module, configured to determine a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism;

[0032] The communication connection module is used to call the communication connection between the local and the target remote communication node through a preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

[0033] In a possible implementation, the preset connection initializer includes node communication attribute data corresponding to each of the plurality of remote communication nodes; the target byte stream data includes: a target communication service type;

[0034] The routing determination module is specifically used for:

[0035] Determining whether the target byte stream data contains the target routing information;

[0036] If the target byte stream data does not contain the target routing information, the target routing information is determined according to the target communication service type and multiple groups of the node communication attribute data.

[0037] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising: a processor, a memory, and a system bus;

[0038] The processor and the memory are connected via the system bus;

[0039] The memory is used to store one or more programs, and the one or more programs include instructions. When the instructions are executed by the processor, the processor executes any possible network communication method in the first aspect.

[0040] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any possible network communication method in the first aspect.

[0041] Compared with the prior art, the present application has the following beneficial effects: the embodiment of the present application provides a network communication method, system, electronic device and medium, in which the target communication data first needs to be encapsulated and processed, and then the target routing information corresponding to the target byte stream data is determined according to the obtained target byte stream data and the preset connection initializer, so as to determine the target remote communication node that needs to perform network communication. Different from the traditional method of selecting routing information first and then assembling data, the present application first assembles data and then performs routing selection and communication connection call, and can select appropriate target routing information according to the actual data situation of the target byte stream data, thereby realizing flexible routing selection strategy and connection pool expansion and contraction mechanism, and retaining great flexibility at the connection layer. Correspondingly, after determining the target routing information, the target connection identifier is determined from the preset working channel group through the target routing information and the target byte stream data, and the communication connection between the local and the target remote communication node is called in combination with the preset asynchronous I / O interface to send the target byte stream data to the target remote communication node, thereby completing the network communication with the target remote communication node. Among them, since the preset working channel group runs based on a single-threaded polling mechanism, combined with the preset asynchronous I / O interface, the call of the communication connection is asynchronous and non-blocking, so as to avoid frequent switching between multiple threads. At the same time, through the operation of the single-threaded polling mechanism, the communication connection for each node is independently carried out. Even if the increase in communication request throughput may cause a bottleneck in the single-threaded performance, it can be dealt with by horizontally expanding the preset working channel group, so as to improve the concurrent processing capability of network communication, thereby achieving the improvement of network communication performance on the basis of taking into account communication flexibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0043] Figure 1 A flowchart of a network communication method provided in an embodiment of the present application;

[0044] Figure 2 A signaling interaction diagram of a network communication method in a JavaScript execution environment of Chrome V8 provided in an embodiment of the present application;

[0045] Figure 3 A flowchart of a method for determining target routing information provided in an embodiment of the present application;

[0046] Figure 4 A flowchart of a method for determining a target connection identifier provided in an embodiment of the present application;

[0047] Figure 5 A schematic diagram of the structure of a network communication system provided in an embodiment of the present application;

[0048] Figure 6 A schematic diagram of the structure of a network communication electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solutions and advantages of this application more clear, the following is a further detailed description of this application in combination with specific embodiments and with reference to the accompanying drawings. It should be noted that the embodiments described in the embodiments of this application are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0050] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present application should be understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in the embodiments of the present application do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "include" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right", etc. are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0051] Just as in the traditional JavaScript execution environment based on Chrome V8, the process of network communication is usually based on HttpClient technology or SocketIO technology. Among them, since the former is based on the short connection method of the Http protocol for communication, short connection means that a new connection needs to be established for each communication, which will bring certain performance overhead in high-performance scenarios with frequent requests, so this type of communication method has certain performance bottlenecks. Correspondingly, although the latter does not have the problem of performance bottlenecks, it lacks flexibility in handling multi-node access and load balancing. The communication connection with each remote node requires additional management and selection, and its communication method has poor flexibility.

[0052] Therefore, how to provide a communication method with both performance and flexibility has become a technical problem that technical personnel in this field urgently need to solve.

[0053] In order to solve the above problems, the embodiment of the present application provides a network communication method, system, electronic device and medium. In the method, first, the target communication data needs to be encapsulated and processed, and then the target routing information corresponding to the target byte stream data is determined according to the obtained target byte stream data and the preset connection initializer, so as to determine the target remote communication node that needs to perform network communication. Different from the traditional method of selecting routing information first and then assembling data, the present application assembles data first and then performs routing selection and communication connection call, and can select appropriate target routing information according to the actual data situation of the target byte stream data, thereby realizing flexible routing selection strategy and connection pool expansion and contraction mechanism, and retaining great flexibility at the connection layer. Correspondingly, after determining the target routing information, the target connection identifier is determined from the preset working channel group through the target routing information and the target byte stream data, and the communication connection between the local and the target remote communication node is called in combination with the preset asynchronous I / O interface to send the target byte stream data to the target remote communication node, thereby completing the network communication with the target remote communication node. Among them, since the preset working channel group runs based on a single-threaded polling mechanism, combined with the preset asynchronous I / O interface, the call of the communication connection is asynchronous and non-blocking, so as to avoid frequent switching between multiple threads. At the same time, through the operation of the single-threaded polling mechanism, the communication connection for each node is independently carried out. Even if the increase in communication request throughput may cause a bottleneck in the single-threaded performance, it can be dealt with by horizontally expanding the preset working channel group, so as to improve the concurrent processing capability of network communication, thereby achieving the improvement of network communication performance on the basis of taking into account communication flexibility.

[0054] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0055] Next, the network communication method provided by the embodiment of the present application will be introduced in conjunction with the specific embodiment drawings. Figure 1 and Figure 2 , Figure 1 A flowchart of a network communication method provided in an embodiment of the present application is provided. Figure 2 A signaling interaction diagram of a network communication method in a JavaScript execution environment of Chrome V8 provided in an embodiment of the present application. Figure 2In the schematic diagram shown, LIBUV-AIO is an extension library that is based on libuv and provides asynchronous I / O (input / output) functions. Libuv itself is a multi-platform, high-performance event-driven I / O library, mainly used in Node.js projects, which is used to provide asynchronous file system operations, network communications, timers, subprocess management and other functions, which corresponds to the preset asynchronous I / O interface in the embodiment of the present application.

[0056] See also Figure 1 , which specifically includes the following steps:

[0057] S101: Perform data assembly processing on target communication data to obtain target byte stream data.

[0058] In the network communication method of the embodiment of the present application, the method can be applied to a JavaScript execution environment based on ChromeV8 (including a client browser and a NodeJS server on the server side). The execution subject of the method is mainly on the server side, and the server side is used to receive the target communication data input by the client through the browser, and perform data assembly processing on the target communication data, convert it into target byte stream data in the form of byte stream, so as to transmit the target byte stream data to the remote communication node, thereby realizing communication services for the client.

[0059] Specifically, in the process of data assembly processing for the target communication data, the target communication data is rearranged into byte streams by the data encoder, so as to deal with the byte order problem when the data is transmitted to the peer service. For example, if the byte order of the client and the peer service is inconsistent, the encoder will rearrange the received byte stream to adapt to the byte order of the local system, so as to ensure the correct transmission and parsing of data between different systems.

[0060] In a possible implementation, in the network communication method of the embodiment of the present application, the data encoder is also responsible for the encapsulation of the custom protocol, which is used to process the encoding of the original data and the byte stream. When the target byte stream data is transmitted through the TCP protocol, the problem of sticky packets may also occur. In order to cope with this problem, the data packet length field can be added to the communication protocol through the data encoder, thereby effectively solving the problem of data packet sticky packets that may be faced when transmitting data based on the TCP protocol, and ensuring the correctness and integrity of the data during the transmission process.

[0061] S102: Based on a preset connection initializer, determine target routing information corresponding to the target byte stream data; the target routing information is used to represent a target remote communication node that needs to perform network communication.

[0062] After the target communication data is assembled to obtain the corresponding target byte stream data, it is necessary to determine the routing information of the target byte stream data, so as to determine the target remote communication node to which the target byte stream data needs to be sent according to the routing information.

[0063] In the network communication scenario of the embodiment of the present application, when the client transmits the target communication data to the server, the target communication service type required by the client will be included in the target communication data, and along with the data assembly for the target communication data, the target communication service type will also be assembled in the byte stream data. In this way, when determining the target routing information based on the preset connection initializer and the target byte stream data, the target communication service type contained in the target byte stream data is analyzed by the preset connection initializer, and combined with the communication attribute data about each remote communication node pre-stored in the preset connection initializer, the target routing information of the target byte stream data can be determined, and the target remote communication node that needs to perform network communication can be determined through the target routing information.

[0064] Next, the process of determining the target routing information by the preset connection initializer in step S102 will be introduced in conjunction with the drawings of the specific embodiments.

[0065] See also Figure 3 , which is a flow chart of a method for determining target routing information provided by an embodiment of the present application, and specifically includes the following steps:

[0066] S1021: Determine whether the target byte stream data contains the target routing information;

[0067] S1022: If the target byte stream data does not contain the target routing information, determine the target routing information according to the target communication service type and multiple groups of the node communication attribute data.

[0068] In the network communication method of the embodiment of the present application, the server needs to identify the communication service type in the communication data based on the communication data input by the client, and send the communication data to the communication node based on the confirmation of the specific remote communication node through the corresponding service type, so as to realize the overall network communication process.

[0069] Therefore, in order to implement a flexible routing strategy as much as possible, the embodiment of the present application adopts a method of assembling data first and then determining the route. The embodiment of the present application pre-stores the communication attribute data corresponding to each remote communication node in the preset connection initialization. These communication attribute data are used to characterize the IP address of the remote communication node, the service type, and the number of connections established for each node, etc.

[0070] Since the target communication data from the client has been pre-assembled into corresponding target byte stream data, the target communication service type contained in the target byte stream data is combined and analyzed with the pre-stored communication data of each remote communication node, thereby determining the corresponding target remote communication node and generating the target routing information.

[0071] This method is different from the traditional network communication method of selecting the route first and then assembling the data. By assembling the data first and then determining the corresponding routing information, the target remote communication node can be determined according to the service type requirements of the communication data and the connection status of each remote communication node, and the corresponding target routing information can be generated based on this, thereby achieving a more flexible routing strategy and improving the flexibility of network communication.

[0072] The above is a detailed introduction to the target routing information determination process in step S102. Figure 1 The network communication method in the embodiment of the present application is introduced:

[0073] S103: Determine a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism.

[0074] In an embodiment of the present application, the preset working channel group is used to save the communication connection information of each remote communication node. Each remote communication node can establish multiple communication connections with the local server. Each communication connection has a corresponding connection identifier (similar to a Socket handle) used to represent the communication connection between the remote communication node and the local server.

[0075] The overall essence of the preset working channel group is an array structure, and its overall structure is a dynamic array, so the size of the array can be adjusted dynamically to achieve the reduction or expansion of the channel group according to the needs of the communication service. The underlying data stored in the preset working channel group is the connection identifier corresponding to each remote communication node. Based on this, in order to refine the storage classification of each connection identifier in the preset working channel group, the present application sets up multiple service connection queues in the preset working channel group, wherein each service connection queue represents a separate communication service type, and each service connection queue contains node identifiers of multiple remote communication nodes. When determining the target routing information, all current connection identifiers of the target remote communication node can be obtained from the preset working channel group according to the target remote communication node indicated in the target routing information, and an available communication connection identifier can be selected therefrom, which can be used as the target connection identifier, thereby providing an index basis for subsequent communication connection calls.

[0076] On the other hand, the preset working channel group runs based on a single-threaded polling mechanism, which is a mechanism that uses a loop in a single thread to check and process events. In this mechanism, the system maintains an event queue, and each loop checks the events in the queue and calls the corresponding processing function. In this way, in the preset working channel group, the management of the queue, the processing of routing information, and the confirmation of the connection identifier are all performed by a single thread. On this basis, when calling a communication connection through the target connection identifier, it is further combined with the preset asynchronous I / O interface for calling, so as to avoid frequent switching between multiple threads and improve the concurrent processing capability and processing performance of network communication.

[0077] Next, the process of determining the target connection identifier by presetting the working channel group in step S103 will be described in conjunction with the accompanying drawings of specific embodiments. Figure 4 , which is a flow chart of a method for determining a target connection identifier provided by an embodiment of the present application, and specifically includes the following steps:

[0078] S1031: Determine a target service connection queue from the plurality of service connection queues according to the target communication service type.

[0079] As can be seen from the foregoing, the target byte stream data includes the target communication service type required for this network communication, and in the preset working channel group, each service connection queue corresponds to a specific communication service type. Therefore, in the process of determining the target connection identifier from the preset working channel group based on the target byte stream data, it is necessary to first determine the target service queue with a matching service type from multiple service connection queues through the target communication service type indicated by the target byte stream data, so as to ensure communication efficiency and accuracy.

[0080] S1032: Determine the target remote communication node from the target service connection queue based on the target routing information;

[0081] S1033: According to the preset working channel group, determine the connection identifier corresponding to the first communication connection as the target connection identifier; the first communication connection is a communication connection that can be currently called by the target remote communication node.

[0082] Further, in the case of determining the target service connection queue, the target remote communication node can be determined from the target service connection queue through the target routing information, and multiple connection identifiers corresponding to the target remote communication node can be viewed. The currently callable communication connection (i.e., the communication connection that maintains a valid connection state) is determined from the multiple connection identifiers, and its corresponding connection identifier is determined as the target connection identifier, so that a call index basis can be established for subsequent communication connection calls.

[0083] The above is the specific process of determining the target connection identifier. Next, continue to combine Figure 1 To introduce:

[0084] S104: calling the communication connection between the local and the target remote communication node through the preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

[0085] Finally, the target connection identifier is used as the index of the communication connection call, and the communication connection indicated by the target connection identifier is called through the underlying preset asynchronous I / O interface, so that the target byte stream data is sent from the local server to the target remote communication node through the communication connection indicated by the target connection identifier, thereby completing the overall network communication process.

[0086] Specifically, the preset asynchronous I / O interface is a programming model that allows the application to return immediately after initiating an I / O operation without waiting for the operation to complete. This means that the application can continue to perform other tasks while the I / O operation is in progress, thereby improving the concurrent processing capability and response speed of the system. Accordingly, since the application will not be blocked due to waiting for the IO operation to complete, the network communication method in the embodiment of the present application can process multiple communication requests at the same time, thereby improving the overall concurrent processing capability.

[0087] After sending the target byte stream data to the target remote communication node, the response data fed back by the target remote communication node in response to the target byte stream data can be further processed based on the event-driven model. Through the event-driven model and data decoder, the corresponding response data can be subjected to the same byte stream re-arrangement processing and data format conversion, thereby relaying the response data of the node to the client.

[0088] In a possible implementation, it can be seen from the introduction of the connection initializer in the previous text that the communication attribute data of each remote communication node is pre-stored in the connection initializer. Therefore, in the initial establishment stage of the working channel group, the connection initializer needs to initialize the communication connection between the local server and each remote communication node according to the communication attribute data of each remote communication node, and send the connection identifier corresponding to each communication connection to the preset working channel group for storage, so as to construct the preset working channel group. The preset working channel group can perform a single-threaded communication connection call according to the connection identifier fed back by the connection initializer, thereby improving the communication performance while ensuring the communication flexibility.

[0089] Accordingly, in another possible implementation, in order to ensure that the connection identifier stored in the working channel group can accurately represent the connection status of the communication connection, the connection status of each communication connection can also be monitored by a heartbeat holder, and the identifier in the working channel group is marked in time when a communication connection fails, so as to prevent the failed communication connection from being called and ensure the accuracy of communication. The specific method of monitoring the connection validity of each communication connection is implemented through the following two steps:

[0090] Step 1: periodically sending a heartbeat signal to each of the remote communication nodes through the communication connection between the local and each of the remote communication nodes, so as to periodically obtain a response signal fed back by the remote communication node.

[0091] Step 2: If the response signal is not received within a preset time period, the corresponding connection identifier is marked as unavailable.

[0092] Monitoring the communication connection between the local server and each remote communication node is a continuous process, which is completed by the heartbeat keeper. The heartbeat keeper periodically sends heartbeat signals to the remote communication node through the communication connection between the local server and each node, and obtains the response signal fed back by the node for the heartbeat signal.

[0093] If no response signal is received from a connection within a preset time, the connection is deemed invalid. In this case, the connection identifier corresponding to the connection is marked as unavailable to prevent the preset working channel group from calling the connection, thereby ensuring the accuracy of network communication.

[0094] The embodiment of the present application provides a network communication method, system, electronic device and medium. In the method, it is first necessary to perform data encapsulation processing on the target communication data, and then determine the target routing information corresponding to the target byte stream data according to the obtained target byte stream data and the preset connection initializer, so as to determine the target remote communication node that needs to perform network communication. Different from the traditional method of selecting routing information first and then assembling data, the present application first assembles data and then performs routing selection and communication connection call, and can select appropriate target routing information according to the actual data situation of the target byte stream data, thereby realizing flexible routing selection strategy and connection pool expansion and contraction mechanism, and retaining great flexibility at the connection layer. Correspondingly, after determining the target routing information, the target connection identifier is determined from the preset working channel group through the target routing information and the target byte stream data, and the communication connection between the local and the target remote communication node is called in combination with the preset asynchronous I / O interface to send the target byte stream data to the target remote communication node, thereby completing the network communication with the target remote communication node. Among them, since the preset working channel group runs based on a single-threaded polling mechanism, combined with the preset asynchronous I / O interface, the call of the communication connection is asynchronous and non-blocking, so as to avoid frequent switching between multiple threads. At the same time, through the operation of the single-threaded polling mechanism, the communication connection for each node is independently carried out. Even if the increase in communication request throughput may cause a bottleneck in the single-threaded performance, it can be dealt with by horizontally expanding the preset working channel group, so as to improve the concurrent processing capability of network communication, thereby achieving the improvement of network communication performance on the basis of taking into account communication flexibility.

[0095] A network communication system provided in an embodiment of the present application is introduced below. The network communication system described below and the network communication method described above can refer to each other.

[0096] See also Figure 5 , which is a schematic diagram of the structure of a network communication system provided in an embodiment of the present application, specifically including the following modules:

[0097] The data assembly module 100 is used to perform data assembly processing on the target communication data to obtain target byte stream data;

[0098] The routing determination module 200 is used to determine the target routing information corresponding to the target byte stream data based on a preset connection initializer; the target routing information is used to characterize the target remote communication node that needs to perform network communication;

[0099] The identification determination module 300 is used to determine the target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism;

[0100] The communication connection module 400 is used to call the communication connection between the local and the target remote communication node through a preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

[0101] In a possible implementation, the preset connection initializer includes node communication attribute data corresponding to each of the plurality of remote communication nodes; the target byte stream data includes: a target communication service type;

[0102] The routing determination module 200 is specifically used for:

[0103] Determining whether the target byte stream data contains the target routing information;

[0104] If the target byte stream data does not contain the target routing information, the target routing information is determined according to the target communication service type and multiple groups of the node communication attribute data.

[0105] See also Figure 6 , which is a schematic diagram of the structure of a network communication electronic device provided by an embodiment of the present application, including:

[0106] A memory 11, used for storing computer programs;

[0107] The processor 12 is used to implement the steps of a network communication method described in any of the above method embodiments when executing the computer program.

[0108] In this embodiment, the device may be a vehicle-mounted computer, a PC (Personal Computer), or a terminal device such as a smart phone, a tablet computer, a PDA, or a portable computer.

[0109] The device may include a memory 11 , a processor 12 , and a bus 13 .

[0110] Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of the device, such as a hard disk of the device. In other embodiments, the memory 11 can also be an external storage device of the device, such as a plug-in hard disk equipped on the device, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Further, the memory 11 can also include both an internal storage unit of the device and an external storage device. The memory 11 can not only be used to store application software installed in the device and various types of data, such as program codes for executing network communication methods, etc., but can also be used to temporarily store data that has been output or is to be output. The processor 12 can be a central processing unit (CPU) in some embodiments.

[0111] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor or other data processing chip, used to run program codes stored in the memory 11 or process data, such as program codes for executing network communication methods.

[0112] The bus 13 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0113] Furthermore, the device may also include a network interface 14, which may optionally include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the device and other electronic devices.

[0114] Optionally, the device may further include a user interface 15, which may include a display (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 15 may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the device and to display a visual user interface.

[0115] Figure 6 Only the device with components 11-15 is shown, and it can be understood by those skilled in the art that Figure 6 The structure shown does not constitute a limitation of the device, and may include fewer or more components than shown, or combine certain components, or arrange the components differently.

[0116] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, an embodiment of the present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the network communication method described in any of the above embodiments.

[0117] The computer-readable media of the embodiments of the present application include permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0118] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the network communication method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0119] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for methods, systems, electronic devices and media, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The methods, systems, electronic devices and media described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components indicated as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0120] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A network communication method, characterized in that: include: Performing data assembly processing on target communication data to obtain target byte stream data; Determine target routing information corresponding to the target byte stream data based on a preset connection initializer; The target routing information is used to characterize the target remote communication node that needs to perform network communication; Determine a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism; The communication connection between the local and the target remote communication node is called through the preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

2. The method according to claim 1, characterized in that The preset connection initializer includes node communication attribute data corresponding to each of the plurality of remote communication nodes; The target byte stream data includes: target communication service type; The determining, based on a preset connection initializer, target routing information corresponding to the target byte stream data comprises: Determining whether the target byte stream data contains the target routing information; If the target byte stream data does not contain the target routing information, the target routing information is determined according to the target communication service type and multiple groups of the node communication attribute data.

3. The method according to claim 2, characterized in that The preset working channel group includes a plurality of service connection queues, each of which has a corresponding communication service type; the service connection queue includes a plurality of remote communication nodes, and each of which corresponds to a plurality of connection identifiers; The step of determining a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data includes: Determining a target service connection queue from the plurality of service connection queues according to the target communication service type; Based on the target routing information, determining the target remote communication node from the target service connection queue; According to the preset working channel group, the connection identifier corresponding to the first communication connection is determined as the target connection identifier; the first communication connection is a communication connection that can be currently called by the target remote communication node.

4. The method according to claim 2, characterized in that: Before the target communication data is subjected to data assembly processing to obtain target byte stream data, the method further comprises: Initializing the communication connection based on the plurality of groups of the node communication attribute data and the preset connection initializer to establish a communication connection between the local and each of the remote communication nodes; The connection identifiers corresponding to the communication connections between the local and each of the remote communication nodes are stored in the preset working channel group.

5. The method according to claim 4, characterized in that The method further comprises: Periodically sending a heartbeat signal to each of the remote communication nodes through a communication connection between the local and each of the remote communication nodes, so as to periodically obtain a response signal fed back by the remote communication node; If the response signal is not received within a preset time period, the corresponding connection identifier is marked as unavailable.

6. The method according to claim 1, characterized in that The step of performing data assembly processing on the target communication data to obtain target byte stream data includes: The target communication data is subjected to byte stream reordering processing by a data encoder to adjust the byte sequence of the target communication data to obtain the target byte stream data.

7. A network communication system, characterized in that: include: A data assembly module is used to perform data assembly processing on target communication data to obtain target byte stream data; A routing determination module, used to determine target routing information corresponding to the target byte stream data based on a preset connection initializer; The target routing information is used to characterize the target remote communication node that needs to perform network communication; An identification determination module, configured to determine a target connection identifier from a preset working channel group according to the target routing information and the target byte stream data; the preset working channel group operates based on a single-threaded polling mechanism; The communication connection module is used to call the communication connection between the local and the target remote communication node through a preset asynchronous I / O interface and the target connection identifier to send the target byte stream data to the target remote communication node.

8. The system according to claim 7, characterized in that The preset connection initializer includes node communication attribute data corresponding to each of the plurality of remote communication nodes; the target byte stream data includes: target communication service type; The routing determination module is specifically used for: Determining whether the target byte stream data contains the target routing information; If the target byte stream data does not contain the target routing information, the target routing information is determined according to the target communication service type and multiple groups of the node communication attribute data.

9. An electronic device, characterized in that: The device comprises: a processor, a memory and a system bus; The processor and the memory are connected via the system bus; The memory is used to store one or more programs, wherein the one or more programs include instructions, and when the instructions are executed by the processor, the processor executes the network communication method according to any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the network communication method described in any one of claims 1 to 6 is implemented.