Inter-process communication method, device, electronic device and medium

By establishing a TCP socket connection between the main program and the subroutine and performing two-way authentication, combined with the JsonBean mechanism and the TinyNET network library, the security issues of inter-process communication in large client projects are solved, and the secure and efficient data transmission between processes is achieved.

CN114817899BActive Publication Date: 2025-09-12NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210422770.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-21
Publication Date
2025-09-12
Estimated Expiration
2042-04-21

AI Technical Summary

Technical Problem

In the development of large-scale client projects, the security of inter-process communication is difficult to guarantee, which can easily lead to information leakage or destructive behavior.

Method used

By integrating the communication server in the main program and the communication client in the subroutine, a TCP socket connection is established, and data transmission is performed after two-way authentication. The JsonBean mechanism is used to construct and parse JSON format data, and the TinyNET network library is used for communication.

Benefits of technology

It ensures the security of inter-process communication, avoids information leakage or destruction caused by subroutines being disguised, and improves the security and efficiency of communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114817899B_ABST
    Figure CN114817899B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a method, device, electronic device and medium for communication between processes, the method comprising: when starting a main program, calling up a communication server integrated in the main program; when detecting that a subprogram of the main program has been started, establishing a TCP socket connection between the main program and the subprogram through the communication server and a communication client integrated in the subprogram; the main program and the subprogram are both stored in the same machine; based on the TCP socket connection, two-way authentication is performed between the main program and the subprogram, and after the authentication is passed, data transmission is performed between the main program and the subprogram based on the TCP socket connection. According to the embodiment of the present invention, through the authentication mechanism, only subprograms that have passed authentication negotiation are allowed to establish a communication connection with the main program for data transmission, which can ensure the security of communication between processes and prevent subprograms from being disguised, causing information leakage or destructive behavior of the main program and subprogram.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an inter-process communication method, an inter-process communication device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In the development of large-scale client projects, inter-process communication technology is often needed. Currently, for inter-process communication within the same machine, the server and client are usually integrated into the process separately. After the connection between the server and the client is established, data communication between the two processes can be carried out. However, the communication security of the above inter-process communication method cannot be guaranteed, which can easily lead to information leakage or destructive behavior between processes. Summary of the Invention

[0003] In view of the above problems, embodiments of the present invention are proposed to provide an inter-process communication method and a corresponding inter-process communication device, an electronic device, and a computer-readable storage medium that overcome the above problems or at least partially solve the above problems.

[0004] An embodiment of the present invention discloses an inter-process communication method, the method comprising:

[0005] When the main program is started, the communication server integrated in the main program is called up;

[0006] When it is detected that the subroutine of the main program is started, a TCP socket connection is established between the main program and the subroutine through the communication server and the communication client integrated in the subroutine; the main program and the subroutine are both stored in the same machine;

[0007] Bidirectional authentication is performed between the main program and the subprogram based on the TCP socket connection, and after the authentication is passed, data transmission is performed between the main program and the subprogram based on the TCP socket connection.

[0008] Optionally, when detecting that the subprogram of the main program is started, establishing a TCP socket connection between the main program and the subprogram through the communication server and a communication client integrated in the subprogram includes:

[0009] When it is detected that the subroutine of the main program is started, the IP address and port of the communication server are sent to the subroutine, so that the subroutine calls the communication client integrated in the subroutine, and establishes the TCP socket connection with the communication server through the communication client according to the IP address and port; the subroutine is started after the main program successfully calls the communication server.

[0010] Optionally, the performing of bidirectional authentication between the main program and the subprogram based on the TCP socket connection includes:

[0011] The communication server receives the TCP socket connection request generated for the IP address and port returned by the communication client, and sends a server confirmation message to the communication client according to the TCP socket connection request;

[0012] The communication server receives a client confirmation message returned by the communication client in response to the server confirmation message, and sends a first negotiation completion message to the communication client according to the client confirmation message.

[0013] The communication server receives a second negotiation completion message returned by the communication client in response to the first negotiation completion message, and sets itself to a ready state according to the second negotiation completion message. The communication server also sends a transmission ready message to the communication client, causing the communication client to set itself to a ready state according to the transmission ready message, thereby completing the two-way authentication.

[0014] Optionally, data transmission between the main program and the subprogram is based on a preset business protocol, the preset business protocol is used to construct and parse JSON format data using a JsonBean mechanism, and the data transmission between the main program and the subprogram based on the TCP socket connection includes:

[0015] When sending a packet based on the TCP socket connection, packaging the transmission data in the JSON format defined by the preset business protocol, and sending the first data block obtained by packaging;

[0016] When receiving packets based on the TCP socket connection, the received second data block is unpacked, and according to the JsonBean class name information contained in the unpacked JSON format transmission data, the target JsonBean class is determined from the container storing the class name information of the unified registrar, and a class instance is created based on the target JsonBean class to store the JSON format transmission data.

[0017] Optionally, the method further includes:

[0018] monitoring the running state of the subprogram, and when it is detected that the subprogram is not running, monitoring the number of crashes of the subprogram within a preset monitoring time range;

[0019] If the number of crashes is not less than a preset first threshold, determining whether to not restart the subprogram or to delay starting the subprogram according to the interval between each crash, and if it is determined that the subprogram should be delayed, extending the time interval of the delayed start;

[0020] If the crash count is less than the preset first threshold, the subroutine is started with a delay, and the time interval of the delayed start is set to a preset value.

[0021] Optionally, the communication client has a corresponding unique session identifier, and the data transmission between the main program and the subprogram based on the TCP socket connection includes:

[0022] When the communication server establishes a TCP socket connection with the plurality of communication clients, determining a target session identifier for data transmission, and determining a target communication client from the plurality of pre-stored communication clients based on the target session identifier;

[0023] Based on the TCP socket connection between the communication server and the target communication client, data transmission is performed between the main program and the target subprogram corresponding to the target communication client.

[0024] Optionally, the communication network library used by the TCP socket connection is the TinyNET network library.

[0025] An embodiment of the present invention further discloses an inter-process communication device, comprising:

[0026] A calling module, used to call the communication server integrated in the main program when starting the main program;

[0027] a communication connection establishing module, configured to establish a TCP socket connection between the main program and the subprogram via the communication server and a communication client integrated in the subprogram upon detecting that the subprogram of the main program has been started; the main program and the subprogram are both stored in the same machine;

[0028] The authentication communication module is used to perform two-way authentication between the main program and the sub-program based on the TCP socket connection, and after the authentication is passed, perform data transmission between the main program and the sub-program based on the TCP socket connection.

[0029] Optionally, the communication connection establishing module includes:

[0030] The sending submodule is used to send the IP address and port of the communication server to the subprogram when it is detected that the subprogram of the main program is started, so that the subprogram calls the communication client integrated in the subprogram, and establishes the TCP socket connection with the communication server through the communication client according to the IP address and port; the subprogram is started after the main program successfully calls the communication server.

[0031] Optionally, the authentication communication module includes:

[0032] A first receiving and sending submodule is configured to receive, by the communication server, a TCP socket connection request generated for the IP address and port returned by the communication client, and to send, by the communication server, a server confirmation message to the communication client according to the TCP socket connection request;

[0033] a second receiving and sending submodule, configured to receive, by the communication server, a client confirmation message for the server confirmation message returned by the communication client, and to send, by the communication server, a first negotiation completion message to the communication client according to the client confirmation message;

[0034] a third receiving and sending submodule, configured to receive, by the communication server, a second negotiation completion message returned by the communication client in response to the first negotiation completion message, and to set the communication server itself to a ready state according to the second negotiation completion message; and to send, by the communication server, a transmission ready message to the communication client, so that the communication client sets itself to a ready state according to the transmission ready message, thereby completing the two-way authentication.

[0035] Optionally, data is transmitted between the main program and the subprogram based on a preset business protocol, and the preset business protocol is used to construct and parse JSON format data using a JsonBean mechanism. The authentication communication module includes:

[0036] a packet sending submodule, configured to package the transmission data in the JSON format defined by the preset business protocol when sending packets based on the TCP socket connection, and send a first data block obtained by packaging;

[0037] The packet receiving submodule is used to unpack the received second data block when receiving packets based on the TCP socket connection, and determine the target JsonBean class from the container storing the class name information in the unified registrar according to the JsonBean class name information contained in the JSON format transmission data obtained by unpacking, and create a class instance based on the target JsonBean class to store the JSON format transmission data.

[0038] Optionally, the device further comprises:

[0039] A monitoring module, configured to monitor the running state of the subprogram and, when it is detected that the subprogram is not running, monitor the number of crashes of the subprogram within a preset monitoring time range;

[0040] a determination module, configured to determine, if the number of crashes is not less than a preset first number threshold, whether to not restart the subprogram or to delay starting the subprogram based on an interval between each crash, and, if it is determined that the subprogram should be delayed, to extend the time interval for delaying the start of the subprogram;

[0041] The delayed start module is used to delay the start of the subroutine if the number of crashes is less than the preset first number threshold, and set the time interval of the delayed start to a preset value.

[0042] Optionally, the communication client has a corresponding unique session identifier, and the authentication communication module includes:

[0043] a determination submodule, configured to determine a target session identifier for data transmission when the communication server establishes a TCP socket connection with the plurality of communication clients, and determine a target communication client from the plurality of pre-stored communication clients based on the target session identifier;

[0044] The communication submodule is used to perform data transmission between the main program and the target subprogram corresponding to the target communication client based on the TCP socket connection between the communication server and the target communication client.

[0045] Optionally, the communication network library used by the TCP socket connection is the TinyNET network library.

[0046] An embodiment of the present invention further discloses an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of the above-mentioned inter-process communication method.

[0047] An embodiment of the present invention further discloses 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 inter-process communication method described above are implemented.

[0048] The embodiments of the present invention include the following advantages:

[0049] In an embodiment of the present invention, a TCP socket connection is established between a main program and a subprogram stored on the same machine using a communication server integrated in the main program and a communication client integrated in the subprogram. Data exchange between the main program and the subprogram is only possible after negotiation and authentication. By employing this method, only subprograms that have undergone authentication and negotiation are allowed to establish a communication connection with the main program for data transmission, ensuring secure inter-process communication and preventing subprograms from being spoofed, potentially leaking information or causing sabotage between the main program and the subprogram. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 This is a flowchart of a method for inter-process communication provided by an embodiment of the present invention;

[0051] Figure 2 is a flowchart of another inter-process communication method provided by an embodiment of the present invention;

[0052] Figure 3 is a flow chart of an inter-process communication method according to an embodiment of the present invention;

[0053] Figure 4 This is a structural block diagram of an inter-process communication device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0054] To make the above-mentioned objects, features, and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments. It is obvious that the embodiments described are only some embodiments of the present invention, rather than all embodiments. All other embodiments obtained by persons of ordinary skill in the art based on the embodiments of the present invention are within the scope of protection of the present invention.

[0055] In the development of large-scale client projects, inter-process communication technology is often needed. Currently, for inter-process communication within the same machine, the server and client are usually integrated into the process separately. After the connection between the server and the client is established, data communication between the two processes can be carried out. However, the communication security of the above inter-process communication method cannot be guaranteed, which can easily lead to information leakage or destructive behavior between processes.

[0056] One of the core concepts of the present invention is that for a main program and subprograms stored on the same machine, a TCP socket connection is established between the main program and subprograms using a communication server integrated in the main program and a communication client integrated in the subprogram. Data exchange between the main program and subprograms is only possible after negotiation and authentication. By adopting this method, only subprograms that have passed authentication and negotiation are allowed to establish a communication connection with the main program for data transmission, ensuring secure inter-process communication and preventing subprograms from being spoofed, which could lead to information leakage or sabotage between the main program and subprograms.

[0057] Reference Figure 1 , shows a flowchart of a method for inter-process communication provided by an embodiment of the present invention, which may specifically include the following steps:

[0058] Step 101: When starting the main program, call up the communication server integrated in the main program.

[0059] The method of the embodiment of the present invention can be applied to client project development. In the development of large-scale client projects, inter-process communication technology is often required. There are many ways to communicate between processes, such as pipes, anonymous pipes (pipes), named pipes (FIFOs), signals (Signal), message queues, shared memory, sockets, etc., and the above methods each have their own advantages and disadvantages.

[0060] Client-developed applications can include a main program and its corresponding subprograms. The main program has a pre-integrated communication server, represented by NIPCserver; the subprogram has a pre-integrated communication client, represented by NIPCclient. The communication server and client can be separated into components, facilitating the integration of the application's main client program and subprograms.

[0061] When the main program is started, the communication server integrated in the main program can be called up, that is, the communication server can be started.

[0062] Step 102: When it is detected that the subprogram of the main program is started, a TCP socket connection is established between the main program and the subprogram via the communication server and the communication client integrated in the subprogram.

[0063] The main program and subprograms may be stored in the same machine.

[0064] In the embodiment of the present invention, sockets are used for inter-process communication. After the communication server is started, the subroutine can be started. After detecting that the subroutine has started, a TCP socket connection can be established between the main program and the subroutine through the communication server integrated in the main program and the communication client integrated in the subroutine.

[0065] In one example, the IP address and port of the communication server can be sent to the subroutine, and then the subroutine calls the communication client pre-integrated in the subroutine. The communication client can establish a TCP socket connection with the communication server based on the IP address and port, thereby establishing a TCP socket connection between the subroutine and the main program.

[0066] Step 103: perform bidirectional authentication between the main program and the sub-program based on the TCP socket connection, and after the authentication is passed, perform data transmission between the main program and the sub-program based on the TCP socket connection.

[0067] In the embodiment of the present invention, after a TCP socket connection is established between the main program and the sub-program, bidirectional authentication between the main program and the sub-program can be performed based on the TCP socket connection.

[0068] For example, after the client main program starts the NIPC server, it then starts the client subprogram and transmits the NIPC server's IP address and port number to the client subprogram via command-line parameters. The client subprogram then establishes a TCP socket connection with the client main program based on the NIPC server's IP address and port number. After the connection is successfully established, the client main program and the client subprogram use a custom handshake authentication method to determine whether the connection is a legitimate inter-process communication connection. Only after successful authentication can inter-process data communication officially begin. Specifically, data communication between the main program and the subprogram can only officially begin after the TCP socket connection between the main program and the subprogram is confirmed to be a legitimate inter-process communication connection.

[0069] In summary, in this embodiment of the present invention, for a main program and subprogram stored on the same machine, a TCP socket connection is established between the main program and the subprogram using a communication server integrated in the main program and a communication client integrated in the subprogram. Data exchange between the main program and the subprogram is only possible after negotiation and authentication. By adopting this method, only subprograms that have passed authentication and negotiation are allowed to establish a communication connection with the main program for data transmission, ensuring secure inter-process communication and preventing subprograms from being spoofed, which could lead to information leakage or sabotage between the main program and the subprogram.

[0070] Reference Figure 2 , shows a flowchart of another inter-process communication method provided by an embodiment of the present invention, which may specifically include the following steps:

[0071] Step 201: When starting the main program, call up the communication server integrated in the main program.

[0072] The method of the embodiment of the present invention can be applied to client project development. The client application developed can include a main program and a subroutine corresponding to the main program. The main program has a pre-integrated communication server, which can be represented by NIPCserver; the subroutine has a pre-integrated communication client, which can be represented by NIPCclient.

[0073] When the main program is started, the communication server integrated in the main program can be called up, that is, the communication server can be started.

[0074] Step 202: When it is detected that the subprogram of the main program is started, a TCP socket connection is established between the main program and the subprogram via the communication server and the communication client integrated in the subprogram.

[0075] The main program and subprograms may be stored in the same machine.

[0076] In the embodiment of the present invention, the subprogram can be started only after the communication server is started. After detecting that the subprogram is started, a TCP socket connection between the main program and the subprogram can be established through the communication server integrated in the main program and the communication client integrated in the subprogram.

[0077] For step 202, the following sub-steps may be performed:

[0078] Sub-step S11, when it is detected that the sub-program of the main program is started, the IP address and port of the communication server are sent to the sub-program, so that the sub-program calls the communication client integrated in the sub-program, and establishes the TCP socket connection with the communication server according to the IP address and port through the communication client.

[0079] Among them, the subroutine is started after the main program successfully calls the communication server.

[0080] In this embodiment of the present invention, the communication server can specify an IP address and port, or use the local IP address. For inter-process communication services running on the same computer, the IP address of that computer can be used as the designated IP address. After the communication server creates the NIPC server TCP transport and obtains the corresponding port, it can use this port as the designated port.

[0081] Before the main program launches a subroutine, it must first start the communication server. Then, it must pass the specified IP address and port number to the subroutine via command-line parameters. The subroutine then calls the integrated communication client. The client then initiates a TCP socket connection request to the communication server based on the specified IP address and port number, establishing a TCP socket connection with the server. The IP address and port number can be stored in the command-line parameters used when the main program launches the subroutine and then transmitted.

[0082] In step 203, the communication server receives the TCP socket connection request generated for the IP address and port and returned by the communication client, and sends a server confirmation message to the communication client according to the TCP socket connection request.

[0083] In an embodiment of the present invention, the communication client integrated in the subroutine can generate a corresponding TCP socket connection request according to the acquired IP address and port, and send the TCP socket connection request to the communication server.

[0084] The communication server integrated in the main program can send a server confirmation message to the communication client according to the received TCP socket connection request.

[0085] Step 204: the communication server receives a client confirmation message returned by the communication client in response to the server confirmation message, and sends a first negotiation completion message to the communication client according to the client confirmation message.

[0086] In the embodiment of the present invention, the communication client integrated in the subroutine may reply a client confirmation message to the communication server according to the received server confirmation message.

[0087] The communication server integrated in the main program may send a first negotiation completion message to the communication client according to the received client confirmation message.

[0088] In step 205, the communication server receives a second negotiation completion message returned by the communication client in response to the first negotiation completion message, and sets itself to a ready state according to the second negotiation completion message. The communication server also sends a transmission ready message to the communication client, causing the communication client to set itself to a ready state according to the transmission ready message, thereby completing the two-way authentication.

[0089] In the embodiment of the present invention, the communication client integrated in the subroutine may reply a second negotiation completion message to the communication server according to the received first negotiation completion message.

[0090] The communication server integrated in the main program can set itself to a ready state according to the received second negotiation completion message, and send a transmission ready message to the communication client.

[0091] The communication client integrated in the subroutine can set itself to a ready state according to the received transmission ready message. At this point, the IPC (Interprocess communication) communication negotiation between the communication server and the communication client is completed.

[0092] Step 206: After the authentication is passed, data transmission between the main program and the sub-program is performed based on the TCP socket connection.

[0093] After the inter-process communication negotiation between the communication server and the communication client is completed, the data communication work between the communication server and the communication client can be officially started.

[0094] In order to enable those skilled in the art to better understand steps 201 to 206 of the embodiment of the present invention, an example is given below to illustrate:

[0095] Reference Figure 3 The flowchart of an inter-process communication method according to an embodiment of the present invention is shown. The communication server integrated in the main program is the NIPC server, and the communication client integrated in the subprogram is the NIPC client. The main program and the subprogram can be integrated with the NIPC server and the NIPC client, respectively. The framework for IPC communication based on the NIPC server and the NIPC client is defined as the NIPC framework. The specific process for implementing inter-process communication is as follows:

[0096] 1. The NIPC server is started in the main program. After the NIPC server is started, the main program transmits the NIPC server's IP and port to the NIPC client through command line parameters when starting the subroutine. The NIPC client initiates a TCP connection establishment request based on the IP and port.

[0097] 2. After receiving the connection request from NIPCclient, NIPC server sends a "serverack" notification to NIPCclient;

[0098] 3. After receiving the "server ack" notification, NIPCclient replies with a "client ack" notification to the NIPC server;

[0099] 4. After receiving the "client ack" notification, the NIPC server sends a "negotiation completed" notification to the NIPC server;

[0100] 5. After receiving the "negotiation completed" notification from the NIPC server, the NIPC client replies with the "negotiation completed" notification to the NIPC server.

[0101] 6. After receiving the "negotiation completed" notification from the NIPC client, the NIPC server sets itself to the ready state and sends a "transport ready" notification to the NIPC client;

[0102] 7. After receiving the "transport ready" notification, NIPCclient sets itself to the ready state, and the IPC communication negotiation is completed. NIPCclient can initiate a customized service protocol request to the NIPC server.

[0103] 8. After receiving the service agreement request from NIPCclient, NIPC server can process it accordingly and respond, or it can actively send notification instructions to NIPCclient.

[0104] For local inter-process communication stored in the same machine, by establishing an authentication mechanism, only subroutines that have passed authentication negotiation are allowed to establish communication connections with the main program for data transmission. This can ensure the security of inter-process communication and prevent subroutines from being disguised, causing information leakage or destructive behavior between the main program and subroutines.

[0105] In an optional embodiment of the present invention, data is transmitted between the main program and the subprogram based on a preset business protocol. The preset business protocol is used to construct and parse JSON format data using the JsonBean mechanism. For step 206, the following steps can be performed:

[0106] Sub-step S21, when sending a packet based on the TCP socket connection, packaging the transmission data in the JSON format defined by the preset business protocol, and sending a first data block obtained by packaging;

[0107] Sub-step S22, when receiving packets based on the TCP socket connection, unpack the received second data block, and determine the target JsonBean class from the container storing the class name information in the unified registrar according to the JsonBean class name information contained in the unpacked JSON format transmission data, and create a class instance based on the target JsonBean class to store the JSON format transmission data.

[0108] In the customized business protocol, a JSON-based business protocol format is adopted, and the JsonBean mechanism is used to implement the conversion between the JSON data of the business protocol layer and the JsonBean Class class of the business application layer, avoiding the tedious JSON construction and parsing process in the development coding work and improving the development efficiency of the business protocol.

[0109] JsonBean has a unified JsonBean Class registrar, JsonBeanMetaRegister, and dispatcher, JsonBeanDispatcher. After defining a specific business JsonBean Class, you need to first register its unique class name with the unified registrar, JsonBeanMetaRegister, to avoid defining JsonBean Class classes with the same name. Internally, std::unordered_map is used to store class registration information. When processing JsonBeanClass in the distributed business logic, its unique class name also needs to be registered with the dispatcher, JsonBeanDispatcher, to achieve accurate distribution and processing of specific business protocols.

[0110] The main interfaces of the JsonBean Class class include:

[0111] (1) Class name acquisition interface: const std::string&JsonBean::ClassName()const;

[0112] (2) Convert from JSON string to JsonBean class interface: JsonBean_UniquePtrJsonBean::FromJsonString(const std::string&json_str);

[0113] (3) Interface for converting from JsonBean class to JSON string: std::string JsonBean::ToJsonString()const;

[0114] (4) Interface for converting from JsonBean class to JSON object: Json::Value JsonBean::ToJsonObject()const.

[0115] When sending packets for inter-process communication based on the established TCP socket connection, the data can be packaged in the JSON format defined by the preset business protocol, and the packaged data blocks can be sent out.

[0116] When receiving packets for inter-process communication based on the established TCP socket connection, the received data block can be unpacked and the JsonBean class name information contained in the unpacked JSON format transmission data can be determined. The corresponding JsonBean class is found in the std::unordered_map container stored in the unified register JsonBeanMetaRegister to store JsonBean class name information. The corresponding class instance is then created to save the parsed JSON format transmission data. At this point, a specific protocol data transmission process of the business layer is completed.

[0117] The inter-process communication currently adopted is to realize the construction and parsing of JSON format data of business protocols based on third-party libraries such as Jsoncpp. In business development, the class of Jsoncpp (such as JsonValue class) is directly used, and the information of each field of JSON data is directly read and written. The process of construction and parsing is relatively cumbersome, and developers need to realize manual coding when building and parsing each time, and development efficiency is low. In the present invention, the automatic construction and parsing of JSON format data are realized by JsonBean mechanism. In business development, the class of Jsoncpp is not directly used, but the self-defined JsonBean class is used. There is no need to read and write the information of each field of Json data. The members defined in the JsonBean class can be directly read and written. By the automatic conversion between the JsonBean class and the JSON format data, the work of manual coding when building and parsing the Json format data each time is avoided, and development efficiency is improved.

[0118] In an optional embodiment of the present invention, the JSON format transmission data may be packaged based on a preset binary serialization protocol, and unpacked based on a preset binary deserialization protocol.

[0119] The TCP socket data transmission of the NIPC framework can use a customized binary serialization protocol and binary deserialization protocol for data transmission. Since the amount of data transmitted in the NIPC framework is small and the confidentiality requirements are not high, the data compression and encryption processes can be omitted, achieving a faster interactive response.

[0120] When sending packets for inter-process communication over an established TCP socket connection, data can be transmitted in the JSON format defined by the preset business protocol, serialized and packaged according to a custom binary serialization protocol, and then sent by calling the socket data sending interface. The header of each data block can include the length of the data block.

[0121] When receiving packets for inter-process communication over an established TCP socket connection, the received data block can be decompressed using a custom binary deserialization protocol, and the resulting JSON-formatted data can be sequentially stored in a cache linked list within the socket data processing wrapper class SocketDataWrapper. The completion of the packet reception process can be determined based on the length information in the received data block header and the length of the decompressed JSON-formatted data in the cache linked list.

[0122] Each data block in the cache list is used to store each complete data block that has been received and unpacked. In the custom communication packet format, the header of each data block contains its data length. When receiving data, the received data block is unpacked according to the custom communication packet format to obtain the block's starting address and length. The completion of each data block's reception and unpacking is determined by whether the block's length matches the length of the data already populated in the cache list. If they are equal, the data block is received and unpacked successfully.

[0123] When receiving data for processing, first check whether the last data block saved in the linked list has been fully received and filled with data. If it has been received, allocate a new empty data block to unpack the new data block and fill it in. Otherwise, continue to use the last data block to receive new data blocks until it has received all the data and is filled. If the data received each time can fill a data block, then after the data block has been received and filled, continue to allocate the next data block to process the remaining unprocessed data received this time, and so on. The cycle continues until all the data received this time has been unpacked and processed. However, it is also possible that the data received each time may not fill up a data block (the received data block is not yet a complete data block). In the case of insufficient filling, it is necessary to wait for the next data to be received to continue filling.

[0124] Once all received data has been unpacked, each complete data block stored in the linked list is retrieved and distributed to the application layer, which then handles the upper-layer services according to the corresponding protocol definitions. The retrieved data blocks are then deleted from the linked list. Incomplete data blocks remain in the linked list, awaiting the next data packet to be filled in until all data is received and unpacked.

[0125] In the NIPC framework, the packet sending and receiving processing mechanisms on the server and client sides are the same, implemented through a common socket data processing encapsulation class SocketDataWrapper. A linked list is used to save received data blocks to ensure the correctness of the processing order, and a processing interface for packet sending and receiving is provided.

[0126] In the present invention, the transmitted data is packaged and unpacked through a custom serialization protocol and a deserialization protocol. Only data that complies with the custom protocol can be packaged or unpacked, which can enhance the security of inter-process communication.

[0127] In an optional embodiment of the present invention, the running status of the subroutine may also be monitored. Specifically, the following steps may be performed:

[0128] Monitor the running status of the subprogram, and when it is detected that the subprogram is in a non-running state, monitor the number of crashes of the subprogram within a preset monitoring time range; if the number of crashes is not less than a preset first number threshold, determine whether to not restart the subprogram or delay the start of the subprogram based on the interval between each crash, and if it is determined that the subprogram is to be delayed, extend the time interval for the delayed start; if the number of crashes is less than the preset first number threshold, delay the start of the subprogram, and set the time interval for the delayed start to a preset value.

[0129] In one example, the NIPC framework also provides a mechanism for automatically monitoring whether the client subroutine being pulled up is alive. If the client subroutine being pulled up crashes abnormally, it will automatically try to re-start it. A timed monitoring mechanism (for example, every 5 seconds) can be enabled to determine whether the client subroutine being pulled up is alive by using a shared memory mechanism between processes, and to optimize the timing of automatically pulling up the client subroutine using a backoff algorithm, thereby avoiding unnecessary frequent pull-up operations when the monitored client subroutine repeatedly crashes abnormally in a short period of time, thereby optimizing the user experience. The main processing flow of the backoff algorithm is as follows:

[0130] (1) Enable the timing (every 5 seconds) monitoring mechanism.

[0131] (2) When the timer reaches its limit, if the client subprogram is in the running state, the delay time interval (delay_restart_time) for restarting the client subprogram is set to 0 seconds, and the next round of survival monitoring is waited for. If the client subprogram is not in the running state, the subprogram crash monitoring is started, and the subprogram crash timing and counting are started.

[0132] (3) If the subroutine crashes 10 or more times, calculate the average time interval between each crash. If the time interval is less than 15 seconds, it is considered that the duration of each crash is too short and no further attempts are made to restart the client subroutine. Otherwise, it is necessary to try to delay the restart of the client subroutine according to the set delay_restart_time. The delay restart time interval can be doubled, and the maximum extension time is limited to 300 seconds.

[0133] (4) If the subroutine crashes less than 10 times, the subroutine is started with a delay, and the time interval for the delayed start is set to a fixed 5 seconds.

[0134] (5) The automatic monitoring timer is destroyed only when the client main program logs out or exits, thereby ensuring that the client subroutine can be pulled up as quickly as possible by the client main program after it exits abnormally.

[0135] In an optional embodiment of the present invention, the communication client has a corresponding unique session identifier. For step 206, the following steps may be performed:

[0136] Sub-step S31, when the communication server establishes a TCP socket connection with a plurality of the communication clients, determining a target session identifier for data transmission, and determining a target communication client from the plurality of pre-stored communication clients based on the target session identifier.

[0137] Sub-step S32: Based on the TCP socket connection between the communication server and the target communication client, data transmission is performed between the main program and the target sub-program corresponding to the target communication client.

[0138] The NIPC framework also supports connection management between a single NIPC server and multiple NIPC clients. Session IDs can be used to distinguish different clients, allowing for simultaneous processing of packet sending and receiving across multiple TCP socket connections, meeting the needs of a wider range of inter-process communication scenarios. Furthermore, the std::unordered_map container can be used to manage session IDs and their corresponding clients, enabling fast lookups.

[0139] In an optional embodiment of the present invention, the communication network library used by the TCP socket connection is the TinyNET network library.

[0140] There are currently many large-scale cross-platform network libraries, such as ACE, Boost.Asio, POCO, etc. However, the present invention does not want to introduce such a large third-party library, nor does it intend to rely on Qt in terms of network libraries. Therefore, the NIPC framework uses the lightweight network library TinyNET (a full-platform network library developed in pure C, derived from the open source client project of DoubangoTelecom) that has been verified by mature products in the industry as the network library for TCP communication, and on this basis, a thin layer of C++ class encapsulation is made for easy use.

[0141] The present invention provides a lightweight, full-platform inter-process communication framework NIPC. The entire communication framework is based on the cross-platform network library TinyNET to implement TCP socket and establish a communication connection between the client main program and the client subprogram.

[0142] All inter-process data communication is based on a custom business protocol. This custom business protocol implementation utilizes a JSON-based business protocol format, which offers excellent scalability. The JsonBean mechanism facilitates the conversion between JSON data in the business protocol layer and JsonBean classes in the business application layer, greatly facilitating calls to the upper business layer and avoiding the tedious JSON construction and parsing required for development coding, thereby improving business protocol development efficiency. The JsonBean mechanism facilitates the serialization and deserialization of business protocol packages.

[0143] The NIPC framework also implements connection management between a single server and multiple clients, distinguishes different clients through session IDs, and can simultaneously handle the packet sending and receiving processes of multiple TCP socket connections, meeting the needs of more inter-process communication business scenarios.

[0144] In addition, the NIPC framework also provides a mechanism for automatically monitoring whether the launched client subprogram is alive and a mechanism for automatically re-launching the client subprogram. It also uses a backoff algorithm to optimize the timing of automatically launching the client subprogram, thereby avoiding unnecessary frequent launch operations when the monitored client subprogram repeatedly crashes abnormally in a short period of time, thereby optimizing the user experience.

[0145] Because the underlying network library TinyNET supports all platforms, the inter-process communication framework NIPC can also be applied to applications with inter-process communication requirements across all platforms. This framework extracts the NIPC server and NIPC client into components, greatly facilitating the integration of the application's client main program and client subprograms.

[0146] In summary, in this embodiment of the present invention, for a main program and subprogram stored on the same machine, a TCP socket connection is established between the main program and the subprogram using a communication server integrated in the main program and a communication client integrated in the subprogram. Data exchange between the main program and the subprogram is only possible after negotiation and authentication. By adopting this method, only subprograms that have passed authentication and negotiation are allowed to establish a communication connection with the main program for data transmission, ensuring secure inter-process communication and preventing subprograms from being spoofed, which could lead to information leakage or sabotage between the main program and the subprogram.

[0147] It should be noted that for the sake of simplicity, the method embodiments are described as a series of actions. However, those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0148] Reference Figure 4 , shows a structural block diagram of an inter-process communication device provided by an embodiment of the present invention, which may specifically include the following modules:

[0149] The calling module 401 is used to call the communication server integrated in the main program when starting the main program;

[0150] a communication connection establishing module 402 for establishing a TCP socket connection between the main program and the subprogram via the communication server and the communication client integrated in the subprogram upon detecting that the subprogram of the main program has been started; the main program and the subprogram are both stored in the same machine;

[0151] The authentication communication module 403 is used to perform two-way authentication between the main program and the sub-program based on the TCP socket connection, and after the authentication is passed, perform data transmission between the main program and the sub-program based on the TCP socket connection.

[0152] In an embodiment of the present invention, the communication connection establishing module includes:

[0153] The sending submodule is used to send the IP address and port of the communication server to the subprogram when it is detected that the subprogram of the main program is started, so that the subprogram calls the communication client integrated in the subprogram, and establishes the TCP socket connection with the communication server through the communication client according to the IP address and port; the subprogram is started after the main program successfully calls the communication server.

[0154] In an embodiment of the present invention, the authentication communication module includes:

[0155] A first receiving and sending submodule is configured to receive, by the communication server, a TCP socket connection request generated for the IP address and port returned by the communication client, and to send, by the communication server, a server confirmation message to the communication client according to the TCP socket connection request;

[0156] a second receiving and sending submodule, configured to receive, by the communication server, a client confirmation message for the server confirmation message returned by the communication client, and to send, by the communication server, a first negotiation completion message to the communication client according to the client confirmation message;

[0157] a third receiving and sending submodule, configured to receive, by the communication server, a second negotiation completion message returned by the communication client in response to the first negotiation completion message, and to set the communication server itself to a ready state according to the second negotiation completion message; and to send, by the communication server, a transmission ready message to the communication client, so that the communication client sets itself to a ready state according to the transmission ready message, thereby completing the two-way authentication.

[0158] In an embodiment of the present invention, data is transmitted between the main program and the subprogram based on a preset business protocol, and the preset business protocol is used to construct and parse JSON format data using the JsonBean mechanism. The authentication communication module includes:

[0159] a packet sending submodule, configured to package the transmission data in the JSON format defined by the preset business protocol when sending packets based on the TCP socket connection, and send a first data block obtained by packaging;

[0160] The packet receiving submodule is used to unpack the received second data block when receiving packets based on the TCP socket connection, and determine the target JsonBean class from the container storing the class name information in the unified registrar according to the JsonBean class name information contained in the JSON format transmission data obtained by unpacking, and create a class instance based on the target JsonBean class to store the JSON format transmission data.

[0161] In an embodiment of the present invention, the device further includes:

[0162] A monitoring module, configured to monitor the running state of the subprogram and, when it is detected that the subprogram is not running, monitor the number of crashes of the subprogram within a preset monitoring time range;

[0163] a determination module, configured to determine, if the number of crashes is not less than a preset first number threshold, whether to not restart the subprogram or to delay starting the subprogram based on an interval between each crash, and, if it is determined that the subprogram should be delayed, to extend the time interval for delaying the start of the subprogram;

[0164] The delayed start module is used to delay the start of the subroutine if the number of crashes is less than the preset first number threshold, and set the time interval of the delayed start to a preset value.

[0165] In an embodiment of the present invention, the communication client has a corresponding unique session identifier, and the authentication communication module includes:

[0166] a determination submodule, configured to determine a target session identifier for data transmission when the communication server establishes a TCP socket connection with the plurality of communication clients, and determine a target communication client from the plurality of pre-stored communication clients based on the target session identifier;

[0167] The communication submodule is used to perform data transmission between the main program and the target subprogram corresponding to the target communication client based on the TCP socket connection between the communication server and the target communication client.

[0168] In the embodiment of the present invention, the communication network library used by the TCP socket connection is the TinyNET network library.

[0169] In summary, in this embodiment of the present invention, for a main program and subprogram stored on the same machine, a TCP socket connection is established between the main program and the subprogram using a communication server integrated in the main program and a communication client integrated in the subprogram. Data exchange between the main program and the subprogram is only possible after negotiation and authentication. By adopting this method, only subprograms that have passed authentication and negotiation are allowed to establish a communication connection with the main program for data transmission, ensuring secure inter-process communication and preventing subprograms from being spoofed, which could lead to information leakage or sabotage between the main program and the subprogram.

[0170] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0171] An embodiment of the present invention also provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned embodiment of the inter-process communication method are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0172] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned embodiment of the inter-process communication method are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0173] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0174] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, apparatus, or computer program products. Thus, embodiments of the present invention may take the form of a fully hardware embodiment, a fully software embodiment, or an embodiment combining software and hardware. Furthermore, embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0175] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the process in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0176] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0177] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0178] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic creative concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0179] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.

[0180] The above is a detailed introduction to an inter-process communication method and an inter-process communication device, an electronic device and a computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A method for communication between processes, characterized in that: The method comprises: When the main program is started, the communication server integrated in the main program is called up; When it is detected that the subroutine of the main program is started, a TCP socket connection is established between the main program and the subroutine through the communication server and the communication client integrated in the subroutine; the main program and the subroutine are both stored in the same machine; Bidirectional authentication is performed between the main program and the subprogram based on the TCP socket connection, and after the authentication is passed, data is transmitted between the main program and the subprogram based on the TCP socket connection; wherein the main program and the subprogram complete the bidirectional authentication when both the communication server and the communication client are in a ready state, the communication server sets itself to the ready state based on a second negotiation completion message sent by the communication client, and the communication client sets itself to the ready state based on a transmission ready message sent by the communication server; monitoring the running state of the subprogram, and when it is detected that the subprogram is not running, monitoring the number of crashes of the subprogram within a preset monitoring time range; If the number of crashes is not less than a preset first threshold, determining whether to not restart the subprogram or to delay starting the subprogram according to the interval between each crash, and if it is determined that the subprogram should be delayed, extending the time interval of the delayed start; If the crash count is less than the preset first threshold, the subroutine is started with a delay, and the time interval of the delayed start is set to a preset value.

2. The method according to claim 1, characterized in that When the subprogram of the main program is detected to be started, a TCP socket connection is established between the main program and the subprogram through the communication server and the communication client integrated in the subprogram, including: When it is detected that the subroutine of the main program is started, the IP address and port of the communication server are sent to the subroutine, so that the subroutine calls the communication client integrated in the subroutine, and establishes the TCP socket connection with the communication server through the communication client according to the IP address and port; the subroutine is started after the main program successfully calls the communication server.

3. The method according to claim 2, characterized in that The bidirectional authentication between the main program and the subprogram based on the TCP socket connection includes: The communication server receives the TCP socket connection request generated for the IP address and port returned by the communication client, and sends a server confirmation message to the communication client according to the TCP socket connection request; The communication server receives a client confirmation message returned by the communication client in response to the server confirmation message, and sends a first negotiation completion message to the communication client according to the client confirmation message. The communication server receives a second negotiation completion message returned by the communication client in response to the first negotiation completion message, and sets itself to a ready state according to the second negotiation completion message. The communication server also sends a transmission ready message to the communication client, causing the communication client to set itself to a ready state according to the transmission ready message, thereby completing the two-way authentication.

4. The method according to claim 1, wherein The data transmission between the main program and the subprogram is based on a preset business protocol, the preset business protocol is used to construct and parse JSON format data using the JsonBean mechanism, and the data transmission between the main program and the subprogram based on the TCP socket connection includes: When sending a packet based on the TCP socket connection, packaging the transmission data in the JSON format defined by the preset business protocol, and sending the first data block obtained by packaging; When receiving packets based on the TCP socket connection, the received second data block is unpacked, and according to the JsonBean class name information contained in the unpacked JSON format transmission data, the target JsonBean class is determined from the container storing the class name information of the unified registrar, and a class instance is created based on the target JsonBean class to store the JSON format transmission data.

5. The method according to claim 1, wherein The communication client has a corresponding unique session identifier, and the data transmission between the main program and the subroutine based on the TCP socket connection includes: When the communication server establishes a TCP socket connection with the plurality of communication clients, determining a target session identifier for data transmission, and determining a target communication client from the plurality of pre-stored communication clients based on the target session identifier; Based on the TCP socket connection between the communication server and the target communication client, data transmission is performed between the main program and the target subprogram corresponding to the target communication client.

6. The method according to claim 1, characterized in that The communication network library used by the TCP socket connection is the TinyNET network library.

7. An inter-process communication device, characterized in that: The device comprises: A calling module, used to call the communication server integrated in the main program when starting the main program; a communication connection establishing module, configured to establish a TCP socket connection between the main program and the subprogram via the communication server and a communication client integrated in the subprogram upon detecting that the subprogram of the main program has been started; the main program and the subprogram are both stored in the same machine; an authentication communication module, configured to perform bidirectional authentication between the main program and the subprogram based on the TCP socket connection, and, after authentication is successful, to perform data transmission between the main program and the subprogram based on the TCP socket connection; wherein the main program and the subprogram complete the bidirectional authentication when both the communication server and the communication client are in a ready state, the communication server sets itself to the ready state based on a second negotiation completion message sent by the communication client, and the communication client sets itself to the ready state based on a transmission ready message sent by the communication server; A monitoring module, configured to monitor the running state of the subprogram and, when it is detected that the subprogram is not running, monitor the number of crashes of the subprogram within a preset monitoring time range; a determination module, configured to determine, if the number of crashes is not less than a preset first number threshold, whether to not restart the subprogram or to delay starting the subprogram based on an interval between each crash, and, if it is determined that the subprogram should be delayed, to extend the time interval for delaying the start of the subprogram; The delayed start module is used to delay the start of the subroutine if the number of crashes is less than the preset first number threshold, and set the time interval of the delayed start to a preset value.

8. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of an inter-process communication method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the inter-process communication method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Program running method and device, terminal and readable medium

    CN109558739A

  • A data transmission method and system

    CN109873831A