Cross-process communication method and device, equipment and storage medium
By pre-binding the communication ports of processes and operating systems in inter-process communication and selecting appropriate communication protocols, the problems of connection maintenance and performance in inter-process communication are solved, and an efficient communication method combining UDP and TCP is realized.
Patent Information
- Application Number
- CN202410504703.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2025-10-24
AI Technical Summary
In cross-process communication, using a single server cannot effectively maintain connection relationships and cannot achieve high-performance communication, especially under UDP and TCP communication methods, where there are problems such as complex link topology or difficulty in maintaining connection relationships.
By pre-binding a process to N communication ports of the operating system, when the binding is successful, the process acts as a cross-process communication server based on UDP and TCP, selects the target communication port to establish a connection with the client process, and selects the appropriate communication protocol to receive or send messages as needed, supporting TCP or UDP.
It achieves high-performance cross-process communication, reduces the number of links, supports TCP connection maintenance, and promptly detects when the server disconnects, thus reducing communication performance consumption.
Smart Images

Figure CN120832250A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of communication, and in particular to a cross-process communication method and device, equipment and a storage medium. BACKGROUND
[0002] In an operating system, a process is a dynamic execution process of a program, that is, the entire life cycle of a program from loading into memory to starting execution until execution is completed. In the running process of the program, corresponding data is generated and saved in the corresponding memory space.
[0003] Since different programs are isolated from each other, different processes have their own memory space and resources, and cannot directly access each other's memory space. When some programs need to share or transfer data, cross-process communication is required. When cross-process communication is performed, the process requesting access acts as a client of the cross-process communication service, and the process being accessed acts as a server of the cross-process communication service. For example, when process A needs to access process B for cross-process communication, process A acts as a client process, and process B acts as a server process to provide services for process A to achieve data access or data sharing.
[0004] However, there are multiple implementation methods for cross-process communication. Since different processes can request access or be accessed, the same process can act as a client of the communication service requesting access or as a server of the communication service being accessed. When there are N servers for cross-process communication, since the process can act as a server process and a client, N x N links need to be maintained, the link topology is complex, and the service is slow.
[0005] In another implementation method, there can also be a single server and multiple clients. When a single server is used, if user datagram protocol (UDP) communication is used, although only N links need to be maintained, the UDP communication method cannot perceive whether the server is offline, which is not conducive to the maintenance of the connection relationship. If transmission control protocol (TCP) communication is used, although only N links need to be maintained, since the connection relationship needs to be maintained, all processes need to use the TCP communication method. Since the TCP communication method needs to add some additional information in the data packet, such as sequence number, acknowledgement number and checksum, etc., this also leads to the fact that the implementation of TCP is more complex than that of UDP, which is not conducive to the scenario where a third-party client only needs to send messages and does not need to receive messages, and high performance cannot be achieved. SUMMARY
[0006] Embodiments of the present application provide a cross-process communication method, device, equipment and storage medium, to solve the problem that connection relationship cannot be maintained and high-performance communication cannot be realized when a single server is used in cross-process communication.
[0007] In a first aspect, the embodiments of the present application provide a cross-process communication method applied to a terminal device, the method comprising:
[0008] When a first process requests to perform cross-process communication, obtaining a pre-binding result between N communication ports of an operating system and the first process;
[0009] Based on the pre-binding result, when it is determined that the N communication ports are all successfully pre-bound with the first process, taking the first process as a server for cross-process communication based on User Datagram Protocol (UDP) and taking the first process as a server for cross-process communication based on Transmission Control Protocol (TCP);
[0010] Selecting one communication port from the N communication ports as a target communication port, and establishing a connection between the target communication port and the first process, so that the first process communicates with at least one second process used by a client associated with the cross-process communication through the target communication port, wherein each second process uses UDP or TCP to perform cross-process communication with the first process.
[0011] In a second aspect, the embodiments of the present application provide a cross-process communication device, comprising:
[0012] The obtaining unit is configured to, when a first process requests to perform cross-process communication, obtain a pre-binding result between N communication ports of an operating system and the first process;
[0013] The determining unit is configured to, based on the pre-binding result, when it is determined that the N communication ports are all successfully pre-bound with the first process, take the first process as a server for cross-process communication based on User Datagram Protocol (UDP) and take the first process as a server for cross-process communication based on Transmission Control Protocol (TCP);
[0014] For the cross-process communication, the selecting unit is configured to select one communication port from the N communication ports as a target communication port, and the establishing unit is configured to establish a connection between the target communication port and the first process, so that the first process communicates with at least one second process used by a client associated with the cross-process communication through the target communication port, wherein each second process uses UDP or TCP to perform cross-process communication with the first process.
[0015] In a possible implementation, the determining unit is further configured to: based on the pre-binding result, establish a connection between each of the M communication ports and the first process, in response to determining that the M communication ports in the N communication ports all fail to be pre-bound with the first process.
[0016] When it is determined according to the connection result that there is one communication port in the M communication ports that successfully connects with the first process, the one communication port that successfully connects is taken as a target communication port, and the first process is taken as a client of the cross-process communication.
[0017] When performing the cross-process communication, the target communication port is used to communicate with a third process used by a server of the cross-process communication.
[0018] In a possible implementation, the determining unit is further configured to determine that a communication port successfully connects with the first process by the following manner:
[0019] controlling the first process to send a connection request to the communication port, the connection request including a port identifier of a server connection of the cross-process communication;
[0020] when a server process associated with the communication interface determines that the port identifier is an identifier of the communication interface, sending verification information to the first process, the verification information including a public key of the server process;
[0021] when the first process successfully verifies according to the public key of the server process, the server process receives verification information sent by the first process, the verification information including a public key of the first process;
[0022] when the server process successfully verifies the public key of the first process, sending a connection response to the first process to determine that the communication port successfully connects with the first process.
[0023] In a possible implementation, before establishing a connection between each of the M communication ports and the first process, the determining unit is further configured to: determine that the first process is a process that needs to send and receive messages.
[0024] When the first process is taken as the client of the cross-process communication, the determining unit is specifically configured to: take the first process as a client of TCP-based cross-process communication.
[0025] In a possible implementation, when it is determined that the first process is a process that only needs to send messages, the determining unit is further configured to:
[0026] determine that the M communication ports are all unsuccessfully pre-bound with the first process based on the pre-binding result, and use the first process as a client of cross-process communication based on UDP;
[0027] When the first process performs cross-process communication, obtain a port identifier corresponding to a server of cross-process communication, and send a request data packet to a communication port corresponding to the port identifier, so that the third process receives the request data packet through the communication port corresponding to the port identifier.
[0028] In another possible implementation, the determining unit is further configured to: when it is determined that the M communication ports are all unsuccessfully connected with the first process according to the connection result, re-establish a connection between the M communication ports and the first process;
[0029] When it is determined that the M communication ports are all unsuccessfully connected with the first process according to the re-obtained connection result, use the first process as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP;
[0030] Select one of the N-M communication ports that are successfully pre-bound as a target communication port, and establish a connection between the target communication port and the first process.
[0031] In a possible implementation, the determining unit is further configured to:
[0032] When cross-process communication is performed between two clients using the second processes, control the first process to receive a request data packet through the target communication port; the request data packet is sent by a second process that is a request side of cross-process communication among the two clients using the second processes, and the request data packet includes process identifier information of a second process that is a receiving side of cross-process communication and request information;
[0033] Control the first process to send the request data packet to the second process that is the receiving side of cross-process communication through the target communication port, to implement cross-process communication between the two clients using the second processes.
[0034] In a possible implementation, the determining unit is further configured to:
[0035] When it is determined that the first process is disconnected from the communication port, select a target second process that is earliest in starting a cross-process communication service time from the at least one second process as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP, and determine a new target communication port;
[0036] The target second process communicates with each second process except the target second process through the new target communication port when performing cross-process communication.
[0037] In a possible implementation, the determining unit is further configured to: when determining that the third process is disconnected from the communication port, select a target first process with the earliest start time of starting the cross-process communication service from at least one first process associated with the cross-process communication service as a service end of the cross-process communication based on UDP and a service end of the cross-process communication based on TCP, and determine a new target communication port;
[0038] Each first process associated with the cross-process communication service and except the target first process is connected to the new target communication port as a client of the cross-process communication respectively.
[0039] Each first process except the target first process communicates with the target first process through the new target communication port when performing cross-process communication.
[0040] In a possible implementation, the disconnection of the first process from the communication port is determined in the following manner:
[0041] When the first process does not receive a data packet or a heartbeat packet within a set time interval, causing the first process to close the cross-process communication service, it is determined that the first process is disconnected from the target communication port; or
[0042] When the first process ends, it is determined that the first process is disconnected from the target communication port.
[0043] In a third aspect, an electronic device is provided, including:
[0044] a memory and a processor;
[0045] The memory is configured to store computer instructions.
[0046] The processor is configured to acquire the computer instructions stored in the memory, and perform the steps of the cross-process communication method according to the computer instructions.
[0047] In a fourth aspect, a computer readable storage medium is provided, which stores computer instructions. When the computer instructions are executed by a processor, the steps of the cross-process communication method are implemented.
[0048] In a fifth aspect, an embodiment of the present application provides a computer program product, which comprises computer instructions stored in a computer readable storage medium; when a processor of an electronic device reads the computer instructions from the computer readable storage medium, the processor executes the computer instructions, so that the electronic device performs the steps of the cross-process communication method provided by an embodiment of the present application.
[0049] The present application has the following beneficial effects:
[0050] In the present application, when cross-process communication is performed between different processes, the process can be determined as a TCP-based cross-process communication server and a UDP-based cross-process communication server when the process is successfully pre-bound with N communication ports of an operating system. At this time, there is only one server in the cross-process communication, which can effectively reduce the number of links.
[0051] The process used by the cross-process communication server can support TCP and UDP protocols, and other processes can communicate with the process used by the server through a TCP communication mode or a UDP communication mode. Therefore, only the third-party application process that needs to send messages is the client of the UDP-based cross-process communication, and does not need to start the server or TCP connection, and directly sends messages through UDP, which can reduce the performance consumption caused by communication to the minimum to achieve high-performance communication. Moreover, since the server supports the TCP communication mode, the connection relationship can be maintained.
[0052] In addition, since the TCP-based cross-process communication server and the UDP-based cross-process communication server use the same process, when the server is disconnected, the client of the UDP-based cross-process communication can also determine that the server of the UDP-based cross-process communication is disconnected in a timely manner.
[0053] In addition, in the traditional mode, the existence of the server is determined by the connection mode, and the connection mode needs to pass through the three-way handshake of TCP, and can be confirmed by the back-and-forth interaction of data, which is time-consuming. The present application determines whether the server exists by binding with multiple local system communication ports, and can immediately know the binding result, thereby effectively shortening the time required to determine whether the server exists.
[0054] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent to those skilled in the art from the description, or can be learned by practice of the present application. The objects and other advantages of the present application can be achieved and obtained by the structure particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0056] Figure 1 An application scenario schematic diagram provided by the embodiments of the present application;
[0057] Figure 2 A cross-process communication schematic diagram provided by the embodiments of the present application;
[0058] Figure 3 A cross-process communication method flowchart provided by the embodiments of the present application;
[0059] Figure 4 A server for cross-process communication schematic diagram provided by the embodiments of the present application;
[0060] Figure 5 A server process and client process communication schematic diagram provided by the embodiments of the present application;
[0061] Figure 6 A communication schematic diagram between two client processes provided by the embodiments of the present application;
[0062] Figure 7 A process and communication port connection schematic diagram provided by the embodiments of the present application;
[0063] Figure 8 A client for cross-process communication schematic diagram provided by the embodiments of the present application;
[0064] Figure 9 Another client for cross-process communication schematic diagram provided by the embodiments of the present application;
[0065] Figure 10 Another server for cross-process communication schematic diagram provided by the embodiments of the present application;
[0066] Figure 11 A process and communication port binding schematic diagram provided by the embodiments of the present application;
[0067] Figure 12 A server and client migration schematic diagram provided by the embodiments of the present application;
[0068] Figure 13 A cross-process communication device schematic diagram provided by the embodiments of the present application;
[0069] Figure 14 A schematic diagram of an electronic device is provided for embodiments of the present application. DETAILED DESCRIPTION
[0070] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and together with the description serve to explain the principles of the present application. In the drawings:
[0071] In order to facilitate those skilled in the art to better understand the technical solutions of the present application, part of the concepts involved in the present application are introduced as follows.
[0072] A process is a running activity of a program on a certain data set in a computer, and is a basic unit of resource allocation and scheduling of a system and a basis of an operating system structure. Different processes are isolated from each other, and an application program cannot directly access objects and variables of different processes.
[0073] Cross-process communication: also known as inter-process communication (IPC), inter-process communication (IPC) is a set of programming interfaces that enable programmers to coordinate different processes so that they can run simultaneously in an operating system and exchange information with each other.
[0074] Transmission Control Protocol: Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. In TCP, data is divided into small blocks called packets or segments for transmission, ensuring that data can be reliably transmitted in the network.
[0075] User Datagram Protocol: User Datagram Protocol (UDP) is a connectionless, unreliable transport layer communication protocol. In UDP, data is divided into small blocks called datagrams for transmission, without guaranteeing the reliability and order of data. UDP does not require a connection to be established before communication begins, and the sender sends datagrams directly to the receiver, each datagram being independent. The header overhead of UDP is small, unlike TCP, which needs to maintain connection state and sequence number information, so the processing overhead is small and the transmission efficiency is high. Due to the low delay and high transmission efficiency of UDP, it is suitable for real-time applications such as audio and video streaming media, online games, and application scenarios that can tolerate data loss or out-of-order.
[0076] UIPC-Server: a server for cross-process communication based on UDP.
[0077] UIPC-Client: Client of the cross-process communication based on UDP.
[0078] TIPC-Server: Server of the cross-process communication based on TCP.
[0079] TIPC-Client: Client of the cross-process communication based on TCP.
[0080] Two-way authentication: Two-way authentication, also known as mutual authentication or mutual authentication, is a security mechanism that requires both parties to authenticate their identities when establishing a connection. In network communication, two-way authentication is used to ensure that communication between the client and the server is secure. After the cross-process communication service connection is successful, the server and the client pass through two-way authentication, and the server authenticates that the client is a trusted source, and the client authenticates that the server is a trusted service.
[0081] The word "exemplary" used in the following means "serving as an example, embodiment or illustration". Any embodiment described as "exemplary" is not necessarily to be construed as superior or better than other embodiments.
[0082] The terms "first", "second" in the text are only for descriptive purposes, and cannot be understood as explicitly or implicitly indicating relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more features, and in the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" is two or more.
[0083] The design idea of the embodiments of the present application is briefly introduced as follows:
[0084] Different programs are isolated from each other, so different processes have their own memory space and resources, and cannot directly access each other's memory space. The operating object in the process of using the terminal includes mobile terminal operating systems such as Android and iOS, PC terminal operating systems such as Windows, Linux and macOS, etc. When some programs need to share or transfer data between each other, cross-process communication is needed. The process of cross-process communication can belong to the same application or different applications.
[0085] Currently, the Android operating system can implement cross-process communication between different application components through AIDL services. The AIDL service allows one application component to call a remote interface provided in another application component, thereby achieving cross-application data exchange and communication. However, due to the characteristics of the AIDL service, if the application does not survive, the system will wake up the application to provide services, which will wake up other applications, and does not meet the compliance requirements. When iOS performs cross-process communication, it is through the notification mode, and can only pass one data, so it does not meet the demand of passing more information. In addition, due to the callback mechanism of the iOS message system including synchronous callback and asynchronous callback, sometimes the data transmission is slow.
[0086] In addition, since different processes can request access or be accessed, the same process can act as both a client of a communication service requesting access and a server of a communication service being accessed, so there is a case of one server or multiple servers in cross-process communication.
[0087] When cross-process communication uses N servers as an example, there will be N x N links, and the link topology is complex, making the service slow.
[0088] When cross-process communication uses a single server, TCP communication can be used, in which case there will be N links, but the implementation is complex, and since the connection relationship needs to be maintained, it is not conducive to scenarios where third-party clients only need to send messages and do not need to receive messages, and high performance cannot be achieved. In addition, UDP communication can also be used, in which case there are N links, but the connection relationship cannot be maintained, that is, the server cannot be timely aware of whether the server is offline. UDP communication can achieve awareness through heartbeat packets, but this increases performance consumption and cannot be timely aware.
[0089] To solve the above problems, the embodiment of the present application provides a cross-process communication method, device, equipment and medium. When a process requests cross-process communication, the process is bound to a port of an operating system. When it is determined that the binding is successful, the process is used as a server of UDP-based cross-process communication and a server of TCP-based cross-process communication. A communication port is selected as a target communication port to establish a connection between the process used by the server and the target communication port. In addition, other processes are used as clients of cross-process communication. According to whether the process needs to receive a message, the process that needs to receive a message is used as a client of TCP-based cross-process communication, and the process that does not need to receive a message and only needs to send a message is used as a server of UDP-based cross-process communication. Then, a connection is established between the process used by the client and the target communication port, so that the process used by the client communicates with the process used by the server through the target communication port. In the present application, cross-process communication is performed in the manner of TCP and UDP, which does not wake up other applications and can transmit more information, supports strings and byte streams. In addition, for a third-party application process that only needs to send a message, the process is used as a UIPC-Client client, and the server does not need to be started, and the TCP connection is not needed. The message is directly sent through UDP, and the performance consumption generated by communication is reduced to the minimum, so as to realize high-performance communication. For other third-party application processes that need to send and receive messages, TCP connection is performed, and connection information can be maintained on the server.
[0090] The preferred embodiments of the present application are described below in conjunction with the accompanying drawings of the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application, and the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0091] Reference Figure 1 , Figure 1 is a schematic diagram of an application scenario of the embodiment of the present application. The application scenario includes an operating system 100. The operating system 100 can be an operating system located on a terminal device. The terminal device includes a mobile terminal and a PC terminal. The mobile terminal includes a smart phone, a tablet computer and the like. When the operating system 100 is an operating system on a mobile terminal, the operating system 100 can be Android or iOS and the like. The PC terminal refers to a personal computer, including a desktop computer and a notebook computer and the like. When the operating system 100 is an operating system on a PC terminal, the operating system 100 can be Windows, Linux, macOS and the like.
[0092] As Figure 1As shown, the operating system 100 includes processes A, B, C, D and E. Among them, process A is both a server (TIPC-Server) of cross-process communication based on TCP and a client (UIPC-Server) of cross-process communication based on UDP. Processes B and C need to send and receive information, so they are clients (TIPC-Client) of cross-process communication based on TCP. Processes D and E only need to send information and do not need to receive information, so they are clients (UIPC-Client) of cross-process communication based on UDP. In this way, the processes D and E are accessed in the lightest way, and the performance consumption generated by communication is minimized, and the processes D and E are suitable for applications with high performance requirements, such as game applications. Among them, process A (process that needs to send and receive information), process B (process that needs to send and receive information) and process C (process that needs to send and receive information) can send and receive information to each other, and processes D (process that only needs to send information) and E (process that only needs to send information) can send information to processes A, B and C.
[0093] In some scenarios, when process D sends information to process B, since both process D and process B are clients, the information can be first sent to process A, and then process A forwards the information to process B, as shown in Figure 2
[0094] Figure 1 and 2 The above is only an example, and in fact, the number of processes for cross-process communication in the operating system is not limited, and is not specifically limited in the embodiments of the present application.
[0095] Based on the above application scenarios, the cross-process communication method provided by the exemplary embodiments of the present application will be described in combination with the above-described application scenarios and the accompanying drawings. It should be noted that the above-described application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the embodiments of the present application are not limited in this respect.
[0096] Referring to Figure 3 Figure 3 An exemplary flowchart of a cross-process communication method in the embodiments of the present application is provided, and the method includes the following steps:
[0097] 301, when a first process requests cross-process communication, obtaining a pre-binding result between N communication ports of an operating system and the first process.
[0098] In some embodiments, when the first process requests to perform cross-process communication, it can be determined whether there is a service end of cross-process communication currently running. Specifically, the first process can be pre-bound with N communication ports of the current operating system through bind pre-binding, and then a pre-binding result is obtained.
[0099] For example, before performing the pre-binding operation, the port numbers and IP addresses corresponding to the N communication ports can be determined. Further, the first process can perform pre-binding operation with the N communication ports through bind pre-binding according to the port numbers and IP addresses of the N communication ports, and then determine whether the pre-binding of each communication port is successful according to the pre-binding result of each communication port.
[0100] Specifically, taking the first communication port as an example, the first process is bind pre-bound with the first communication port. When it is determined that the pre-binding result between the first communication port and the first process is a success code or a success state, it is determined that the pre-binding between the first communication port and the first process is successful. The success code or success state can be a constant, a numerical value, or a Boolean value. When it is determined that the pre-binding result between the first communication port and the first process is an error code or an error message, it is determined that the pre-binding between the first communication port and the first process fails. The error code can be that the communication port is already occupied, the bound address is unavailable, the permission is insufficient, etc. The error message is usually returned in the form of a string, which contains detailed description of the error.
[0101] In this application, when the first process is pre-bound with the N communication ports of the current operating system, the first process can be simultaneously pre-bound with the N communication ports, or the first process can be pre-bound with the communication ports one by one, or the first process can be pre-bound with the N communication ports in batches, which is not limited in this application.
[0102] 302, based on the pre-binding result, when it is determined that the N communication ports are all successfully pre-bound with the first process, the first process is taken as a service end of cross-process communication based on user datagram protocol (UDP), and the first process is taken as a service end of cross-process communication based on transmission control protocol (TCP).
[0103] In some embodiments, when the N communication ports are all successfully pre-bound with the first process, it indicates that there is no service end of cross-process communication currently running in the current operating system, and at this time, the first process can be taken as a service end of cross-process communication. Specifically, the first process can be taken as a service end of cross-process communication based on TCP, which is responsible for communicating with a client process of cross-process communication which needs to send and receive information. At the same time, the first process can be taken as a service end of cross-process communication based on UDP, which is responsible for communicating with a client process which only needs to send information.
[0104] 303. selecting one of the N communication ports as a target communication port, and establishing a connection between the target communication port and the first process, so that the first process communicates with at least one second process used by a client for cross-process communication through the target communication port, wherein each second process uses UDP or TCP for cross-process communication with the first process.
[0105] In some embodiments, when the N communication ports are all successfully bound, any one of the N communication ports can be selected as the target communication port. As shown in Figure 4 When the N communication ports are all successfully bound, port 1 can be selected as the target communication port, and a connection is established between the target communication port and the first process, so that the second process used as a client communicates with the first process through port 1. As shown in Figure 5 Taking process 1 as the first process and process 2 as the second process as an example, a connection is established between process 1 and port 1. When process 2 needs to perform cross-process communication, it can communicate with process 1 through port 1.
[0106] In some scenarios, after port 1 establishes a connection with process 1, process 1 listens through port 1 to receive data packets received by port 1.
[0107] In some embodiments, when the second processes used by two clients perform cross-process communication, the first process is controlled to receive a request data packet through the target communication port. The request data packet is sent by a second process used by a client as a request side of cross-process communication, and the request data packet includes process identification information of a second process used by a client as a receiving side of cross-process communication and request information. Further, the first process can be controlled to send the request data packet to the second process used by the client as the receiving side of cross-process communication through the target communication port, to implement cross-process communication between the second processes used by the two clients.
[0108] As an example, process 1 is a server process, and process 2 and process 3 are client processes. Process 1 performs cross-process communication with process 2 and process 3 through port 1. When process 2 requests to perform cross-process communication with process 3, process 2 sends a data packet 1 to port 1 as a request side process. The data packet 1 includes process identification of process 3 and request information. When process 1 listens to the data packet 1 sent by process 2 through port 1, it sends the data packet 1 to process 3 through port 1 according to the process identification in the data packet 1, to implement cross-process communication between the two client processes, as shown in Figure 6
[0109] In a possible implementation, based on the pre-binding result, when it is determined that M communication ports in the N communication ports all fail to be pre-bound with the first process, a connection is established between the M communication ports and the first process respectively. When it is determined, according to the connection result, that there is one communication port in the M communication ports that succeeds in connecting with the first process, the one communication port that succeeds in connecting is taken as a target communication port, and the first process is taken as a client of cross-process communication. Further, when the cross-process communication is performed, the target communication port is used to communicate with a third process used by a server of the cross-process communication.
[0110] In some embodiments, before the connection is established between the M communication ports and the first process respectively, it is further needed to determine that the first process is a process that needs to send and receive messages. Further, when it is determined that the first process is the process that needs to send and receive messages, the first process is taken as a client of cross-process communication based on TCP.
[0111] In some embodiments, when it is determined that the first process is a process that only needs to send messages, after it is determined, based on the pre-binding result, that M communication ports in the N communication ports all fail to be pre-bound with the first process, the first process is taken as a client of cross-process communication based on UDP. When the first process performs cross-process communication, a port identifier corresponding to a server of the cross-process communication is acquired, and a request data packet is sent to a communication port corresponding to the port identifier, so that the third process receives the request data packet through the communication port corresponding to the port identifier.
[0112] In the present application, before it is determined to use the UDP communication mode, it is needed to determine whether the application program needs to send and receive messages. If the application program needs to send and receive messages, the TCP communication mode is used, and the TCP communication mode needs to establish a connection to ensure the safety of the communication link. If the application program only needs to send messages and does not need to receive messages, the UDP communication mode can be used, and the UDP communication mode does not need to establish a connection, that is, whether the communication link is safe or not is not considered, and messages can be directly sent to the server.
[0113] Through the above scheme, when an application process that only needs to send messages performs cross-process communication, the UDP communication mode is used, and messages can be directly sent, without the process of connection establishment, so that the access is kept lightest, and the performance consumption caused by communication is reduced to the minimum.
[0114] Specifically, when it is determined, based on the pre-binding result, that part of the communication ports succeed in pre-binding and part of the communication ports fail in pre-binding, that is, there are failed ports when the bind is performed, it is indicated that the server of cross-process communication is possibly running. Further, the first process can be connected with the failed communication ports through the mode of IO multiplexing.
[0115] For example, when it is determined that M communication ports of N communication ports are all failed to be pre-bound with the first process, a connection is established between the M communication ports and the first process, respectively.
[0116] In some embodiments, the connection between the communication port and the first process can be determined by the following method:
[0117] The first process is controlled to send a connection request to the communication port, wherein the connection request comprises a port identifier of a server connection of the cross-process communication. For example, taking the communication port as port 1, the first process sends a connection request, and the connection request comprises the port identifier 1 of the server associated with the cross-process communication. In some scenarios, the connection request can also comprise an IP address. When the inter-process communication is performed in the same terminal device, the IP addresses of different processes are the same, and thus, no specific description is made herein.
[0118] Further, when the server process associated with the communication interface determines that the port identifier is the identifier of the communication interface, the server process sends verification information to the first process, and the verification information comprises a public key of the server process. When the first process is verified successfully according to the public key of the server process, the server process receives the verification information sent by the first process, and the verification information comprises a public key of the first process. Further, when the server process verifies the public key of the first process successfully, a connection response is sent to the first process to determine that the connection between the communication port and the first process is successful.
[0119] Taking the above example, the server process receives the connection request of the first process through the port 1. When the server process determines that the port identifier 1 in the connection request is the port identifier of the port 1, it can be determined that the server process is the third process in which the server of the cross-process communication is located.
[0120] Further, the server process sends verification information comprising the public key 1 of the server process to the first process. When the first process verifies the server process successfully according to the verification information, the first process sends verification information comprising the public key 2 of the first process to the server process. Further, when the server process verifies the public key 2 of the first process successfully, the server process sends a connection response to the first process, as shown in Figure 7 At this time, the first process is successfully connected with the port 1, or it can be understood that the first process is successfully connected with the process used by the server of the cross-process communication.
[0121] As an example, when it is determined according to the pre-binding result that port 1, port 2 and port 4 fail to be pre-bound, connections are established between port 1, port 2 and port 4 and the first process respectively, and bidirectional authentication is performed. When the connection result is that port 1 succeeds in connection and port 2 and port 4 fail, the first process is taken as a client (TIPC-Server) of cross-process communication. When cross-process communication is performed, communication is performed with a third process in which a server of cross-process communication is located through port 1, as shown in Figure 8 .
[0122] In some embodiments, when it is determined according to the connection result that the M communication ports all fail to be connected with the first process, connections are established again between the M communication ports and the first process. In some scenarios, the connection can be retried M times. Further, when it is determined according to the re-obtained connection result that there is one communication port that succeeds in connection, the first process is taken as a client of cross-process communication based on TCP. When cross-process communication is performed, communication is performed with a third process in which a server of cross-process communication is located through the communication port that succeeds in connection.
[0123] For example, when it is determined according to the pre-binding result that port 1, port 2 and port 4 fail to be pre-bound, connections are established between port 1, port 2 and port 4 and the first process respectively, and bidirectional authentication is performed. When none of the communication ports succeeds in bidirectional authentication after a timeout, i.e., all the connections fail, the connection is retried three times again. When it is determined that port 1 that fails to be bound succeeds in connection, process 1 is connected to a TIPC-Server of cross-process communication service using port 1 as a TIPC-Client, as shown in Figure 9 .
[0124] In some embodiments, when it is determined again according to the re-obtained connection result that the M communication ports all fail to be connected with the first process, the first process is taken as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP. Further, one of the N-M communication ports that succeed in pre-binding is selected as a target communication port, and a connection is established between the target communication port and the first process.
[0125] As an example, when it is determined that port 1, port 2 and port 4 fail to be pre-bound among N communication ports, connections are established between port 1, port 2 and port 4 and the first process respectively, and bidirectional authentication is performed. When the connection result is that none of the ports that fail to be bound succeeds in bidirectional authentication after multiple retries, one of the communication ports that succeed in binding is selected as a target communication port, and the first process is taken as a server of cross-process communication. For example, port 3 can be selected as the target port, and communication is performed with a client of cross-process communication using port 2, as shown in Figure 10As shown. At this time, the first process can support TCP communication and UDP communication.
[0126] Based on the above scheme, when the connection fails, the connection can be retried multiple times to prevent misjudgment of connection failure, thereby causing the existence of multiple cross-process communication servers at the same time.
[0127] In some embodiments, if after multiple retries, none of the failed communication ports through bidirectional authentication. For the case of all port binding failures, the N ports tried can be changed to N+1 to N+N ports, that is, the port range is changed, and after a period of time, the pre-binding operation is performed again, such as Figure 11 As shown.
[0128] As an example, the maximum value of the first pre-bound communication port is port N, and if the pre-binding result is that port 1-port N pre-binding fails, respectively, the connection between port 1-port N is established and bidirectional authentication is performed. After multiple connections, the connection result is that no port connection fails, at this time, the port range is expanded, that is, the maximum value of the second pre-bound communication port is port N+N. After setting the interval, the second pre-binding is performed, and then the process and port N+1-port N+N are pre-bound, and the pre-binding result is obtained. If port N+1-port N+N pre-binding fails, then after setting the interval, that is, when the third pre-binding is performed, the port 2N+1-port 2N+N is pre-bound with the process.
[0129] Based on the above scheme, the present application determines whether there is a cross-process communication server by trying to bind the pre-binding method, first judges whether the port can be bound, if the port binding fails, then try to connect, compared with the method of judging whether the server exists by connecting in the prior art, because the connection needs data interaction, therefore, the present application adopts the bind binding method, which can effectively shorten the time required to judge whether the server exists. In addition, in the prior art, only a fixed single port is used for networking, and all servers and clients will use this port for communication. In the present application, during initialization, N standby ports will be detected at the same time, if they are occupied by non-cross-process communication services, the standby port will be automatically selected.
[0130] In some embodiments, when it is determined that the third process is disconnected from the communication port, from the at least one first process associated with the cross-process communication service, a target first process with the earliest start time of the cross-process communication service is selected as a service end of the cross-process communication based on UDP and the cross-process communication based on TCP, and a new target communication port is determined. Each first process associated with the cross-process communication service except the target first process is connected to the new target communication port respectively, and the target first process communicates with each first process except the target first process through the new target communication port when the cross-process communication is performed.
[0131] In some embodiments, when the first process as a service end of the cross-process communication communicates with at least one second process associated with the cross-process communication, when it is determined that the first process is disconnected from the communication port, a target second process with the earliest start time of the cross-process communication service is selected from the at least one second process as a service end of the cross-process communication based on UDP and the cross-process communication based on TCP, and a new target communication port is determined. The target second process communicates with each second process except the target second process through the new target communication port when the cross-process communication is performed.
[0132] Specifically, the disconnection of the first process from the target communication port can be determined in the following manner:
[0133] When the first process does not receive a data packet or a heartbeat packet within a set time interval, the first process closes the cross-process communication service, and it is determined that the target communication port is disconnected; or when the first process ends, it is determined that the first process is disconnected from the target communication port.
[0134] In some embodiments, during the running of the cross-process communication service, the service end process as a TIPC-Server and a UIPC-Server sends a heartbeat packet to itself at a set time interval to determine whether the process is alive.
[0135] In an embodiment, the service end process sends a heartbeat packet to itself at a set time interval. When it is determined that the last heartbeat packet is received, if a data packet is received within the set time interval, the heartbeat packet does not need to be sent to itself again to reduce performance consumption. Then, whether a data packet or a heartbeat packet is received within the next set time interval is determined.
[0136] If the server process of cross-process communication does not receive the heartbeat packet or the data packet for a certain time, it is considered that the server process connection is disconnected. Other TCP-based cross-process communication clients will immediately perceive the network disconnection and will close the connection. Further, the establishment of the cross-process communication service for at least one client (TIPC-Client) process determines a new cross-process communication server to achieve the effect of smooth migration. Then, other TCP-based client processes are connected to the new cross-process communication server process, and the UDP-based client processes directly send information to the new cross-process communication server when sending messages.
[0137] As an example, the operating system includes processes A, B, C, D and E, wherein process A is a cross-process communication server and provides services for cross-process communication-based clients. Processes B and C are TIPC-Client and are connected to process A, and processes D and E send messages to process A. When the service of process A is closed, the connection between processes B and C and process A is closed, and one of processes B and C is selected as a server process as TIPC-Server and UIPC-Client. Wherein, process C starts the cross-process communication service earlier than process C. Process C is taken as a cross-process communication server and the service is started. Further, process B will be reconnected to process C, and processes D and E will send to process C when sending messages, as shown in Figure 12 .
[0138] Please refer to Figure 13 , Figure 13 An embodiment of the present application exemplarily provides a cross-process communication device 1300, which comprises:
[0139] An obtaining unit 1301 is configured to obtain a pre-binding result between N communication ports of an operating system and a first process when the first process requests to perform cross-process communication;
[0140] A determining unit 1302 is configured to, based on the pre-binding result, determine that the N communication ports are all pre-bound to the first process successfully, take the first process as a server of cross-process communication based on user datagram protocol (UDP), and take the first process as a server of cross-process communication based on transmission control protocol (TCP);
[0141] select one communication port from the N communication ports as a target communication port, and establish a connection between the target communication port and the first process, so that the first process communicates with a second process used by at least one client associated with the cross-process communication through the target communication port.
[0142] Each of the second processes uses UDP or TCP to perform cross-process communication with the first process.
[0143] In a possible implementation, the determining unit 1302 is further configured to:
[0144] Based on the pre-binding result, when it is determined that M communication ports in the N communication ports all fail to be pre-bound with the first process, a connection is established between each of the M communication ports and the first process.
[0145] When it is determined according to a connection result that there is one communication port in the M communication ports that is successfully connected with the first process, the one communication port that is successfully connected is taken as a target communication port, and the first process is taken as a client of the cross-process communication.
[0146] When performing cross-process communication, the target communication port is used to communicate with a third process used by a server of the cross-process communication.
[0147] In a possible implementation, the determining unit 1302 is further configured to:
[0148] The communication port is determined to be successfully connected with the first process in the following manner:
[0149] The first process is controlled to send a connection request to the communication port, and the connection request includes a port identifier of a server connection of cross-process communication.
[0150] When a server process associated with the communication interface determines that the port identifier is an identifier of the communication interface, verification information is sent to the first process, and the verification information includes a public key of the server process.
[0151] When the first process is successfully verified according to the public key of the server process, the server process receives verification information sent by the first process, and the verification information includes a public key of the first process.
[0152] When the server process is successfully verified with the public key of the first process, a connection response is sent to the first process to determine that the communication port is successfully connected with the first process.
[0153] In a possible implementation, before the connection is established between each of the M communication ports and the first process, the determining unit 1302 is further configured to determine that the first process is a process that needs to send and receive messages.
[0154] The determining unit 1302 is specifically configured to determine the first process as a client of TCP-based cross-process communication.
[0155] In a possible implementation, when it is determined that the first process is a process that only needs to send a message, the determining unit 1302 is further configured to:
[0156] determine the first process as a client of UDP-based cross-process communication, based on the pre-binding result.
[0157] When the first process performs cross-process communication, the port identifier corresponding to a server of cross-process communication is acquired, and a request data packet is sent to a communication port corresponding to the port identifier, so that the third process receives the request data packet through the communication port corresponding to the port identifier.
[0158] In another possible implementation, the determining unit 1302 is further configured to: when it is determined according to the connection result that the M communication ports all fail to connect with the first process, connection between the M communication ports and the first process is established again.
[0159] When it is determined according to the re-obtained connection result that the M communication ports all fail to connect with the first process again, the first process is determined as a server of UDP-based cross-process communication and a server of TCP-based cross-process communication.
[0160] One of the N-M communication ports that successfully pass the pre-binding is selected as a target communication port, and connection between the target communication port and the first process is established.
[0161] In a possible implementation, the determining unit 1302 is further configured to:
[0162] When cross-process communication is performed between two client-used second processes, the first process is controlled to receive a request data packet through the target communication port, wherein the request data packet is sent by a second process that is a request side of cross-process communication among the two client-used second processes, and the request data packet includes process identifier information of a second process that is a receiving side of cross-process communication and request information.
[0163] The first process is controlled to send the request data packet to the second process that is the receiving side of cross-process communication through the target communication port, so as to implement cross-process communication between the two client-used second processes.
[0164] In a possible implementation, the determining unit 1302 is further configured to:
[0165] when determining that the first process is disconnected from the communication port, selecting, from the at least one second process, a target second process that starts a cross-process communication service earliest in time as a server of the cross-process communication based on UDP and a server of the cross-process communication based on TCP, and determining a new target communication port;
[0166] the target second process communicates with each second process except the target second process through the new target communication port when performing the cross-process communication.
[0167] In a possible implementation, the determining unit 1302 is further configured to:
[0168] when determining that the third process is disconnected from the communication port, selecting, from the at least one first process associated with the cross-process communication service, a target first process that starts a cross-process communication service earliest in time as a server of the cross-process communication based on UDP and a server of the cross-process communication based on TCP, and determining a new target communication port;
[0169] each first process associated with the cross-process communication service except the target first process is connected to the new target communication port respectively as a client of the cross-process communication;
[0170] each first process except the target first process communicates with the target first process through the new target communication port when performing the cross-process communication.
[0171] In a possible implementation, the first process is determined to be disconnected from the communication port in the following manner:
[0172] when the first process does not receive a data packet or a heartbeat packet within a set time interval, causing the first process to close the cross-process communication service, it is determined that the first process is disconnected from the target communication port; or
[0173] when the first process ends, it is determined that the first process is disconnected from the target communication port.
[0174] After the cross-process communication method and device of the example embodiments of the present application are introduced, next, an electronic device for cross-process communication according to another example embodiment of the present application is introduced.
[0175] Based on the same inventive concept as the method embodiments described above, an electronic device is further provided in the embodiments of the present application. In this embodiment, the structure of the electronic device can be as follows Figure 14As shown, it includes a memory 1401 and one or more processors 1402.
[0176] Memory 1401 is used to store computer programs executed by processor 1402. Memory 1401 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and programs required for running instant messaging functions, while the data storage area may store various instant messaging messages and operating instruction sets.
[0177] Memory 1401 may be a volatile memory, such as random-access memory (RAM); a non-volatile memory, such as read-only memory, flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); or any other medium capable of carrying or storing a desired computer program in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 1401 may be a combination of the aforementioned memories.
[0178] The processor 1402 may include one or more central processing units (CPUs) or digital processing units, etc. The processor 1402 is configured to implement the above-mentioned cross-process communication method when calling the computer program stored in the memory 1401 .
[0179] The specific connection medium between the memory 1401 and the processor 1402 is not limited in the embodiment of the present application. Figure 14 In the embodiment, the memory 1401 and the processor 1402 are connected via a bus 1403. Figure 14 The connections between the other components are shown in bold lines, which are only for illustration and are not intended to be limiting. The bus 1403 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Figure 14 The diagram shows a single thick line, but this does not indicate that there is only one bus or one type of bus.
[0180] The memory 1401 stores a computer storage medium, which stores computer executable instructions for implementing the inter-process communication method of the embodiment of the present application. The processor 1402 is used to execute the above inter-process communication method.
[0181] In some possible implementation, each of the aspects of the cross-process communication method provided by the present application can also be implemented in the form of a program product, which includes a computer program for causing an electronic device to perform the steps of the cross-process communication method according to various exemplary embodiments of the present application described above in the specification when the program product is run on the electronic device.
[0182] The program product can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium may, for example, but is not limited to, an electrical, a magnetic, an optical, an electromagnetic, an infrared, or a semiconductor system, device or apparatus, or any suitable combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include an electrical connection having one or more wires, a portable disc, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or a flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0183] The program product of the embodiments of the present application can adopt a portable compact disc read-only memory (CD-ROM) and include a computer program, and can be run on a computing device. However, the program product of the present application is not limited thereto, and in the present document, the readable storage medium can be any tangible medium containing or storing a program, which can be used or combined with a command execution system, device or apparatus.
[0184] The readable signal medium can include a data signal carried in a baseband or as a part of a carrier wave, in which a readable computer program is borne. Such a propagated data signal can take on multiple forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable signal medium can also be any readable medium that is not a readable storage medium and that can transmit, propagate, or transport a program for use by or in connection with a command execution system, device or apparatus.
[0185] The computer program contained on the readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination of the above.
[0186] It should be noted that although several units or sub-units of the apparatus are mentioned in the above detailed description, such a division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units for embodiment.
[0187] Moreover, although the operations of the method(s) herein can be described in a particular, sequential order, this order is not meant to be a limitation and
[0188] Those of skill in the art would understand that embodiments of the present application can be provided as a method, system, or computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer readable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer readable program code.
[0189] The present application is described in reference to the flowchart illustrations and / or block diagrams of methods, apparatus (systems) and computer program products according to this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart Figure 1 one or more functions specified in the flowchart block or blocks. Figure 1 one or more functions specified in the flowchart block or blocks.
[0190] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks. Figure 1 one or more functions specified in the flowchart block or blocks. Figure 1 one or more functions specified in the flowchart block or blocks.
[0191] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the function specified in the flowchart block or blocks. Figure 1 one or more functions specified in the flowchart block or blocks. Figure 1 one or more functions specified in the flowchart block or blocks.
[0192] Obviously, many modifications and variations of the present application are possible in light of the above teachings. It is, therefore, to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.
Claims
1. A cross-process communication method, characterized by, The method is applied to a terminal device, and comprises the following steps: When a first process requests to perform cross-process communication, a pre-binding result between N communication ports of an operating system and the first process is obtained; Based on the pre-binding result, when it is determined that the N communication ports are all successfully pre-bound with the first process, the first process is taken as a server of cross-process communication based on a user datagram protocol (UDP), and the first process is taken as a server of cross-process communication based on a transmission control protocol (TCP); A target communication port is selected from the N communication ports, and a connection is established between the target communication port and the first process, so that the first process communicates with a second process used by at least one client associated with the cross-process communication through the target communication port, wherein each second process uses UDP or TCP to perform cross-process communication with the first process.
2. The method of claim 1, wherein, The method further comprises the following steps: Based on the pre-binding result, when it is determined that M communication ports of the N communication ports are all unsuccessfully pre-bound with the first process, a connection is established between the M communication ports and the first process, respectively; When it is determined according to a connection result that there is one communication port of the M communication ports that is successfully connected with the first process, the one communication port is taken as a target communication port, and the first process is taken as a client of the cross-process communication; When performing cross-process communication, the first process communicates with a third process used by a server of cross-process communication through the target communication port.
3. The method of claim 2, wherein, The one communication port is successfully connected with the first process by the following steps: The first process sends a connection request to the communication port, and the connection request comprises a port identifier of a server connection of cross-process communication; When a server process associated with the communication interface determines that the port identifier is an identifier of the communication interface, the server process sends verification information to the first process, and the verification information comprises a public key of the server process; When the first process is successfully verified according to the public key of the server process, the server process receives verification information sent by the first process, and the verification information comprises a public key of the first process; When the server process is successfully verified with respect to the public key of the first process, a connection response is sent to the first process to determine that the communication port is successfully connected with the first process.
4. The method of claim 2, wherein, Before the connection is established between the M communication ports and the first process, respectively, the method further comprises the following steps: It is determined that the first process is a process that needs to send and receive messages; The first process is taken as a client of cross-process communication based on TCP. When it is determined that the first process is a process that only needs to send messages, the method further comprises the following steps:
5. The method of claim 2, wherein, After it is determined that M communication ports of the N communication ports are all unsuccessfully pre-bound with the first process based on the pre-binding result, the first process is taken as a client of cross-process communication based on UDP; When the first process performs cross-process communication, a port identifier corresponding to a server of the cross-process communication is acquired, and a request data packet is sent to a communication port corresponding to the port identifier, so that the third process receives the request data packet through the communication port corresponding to the port identifier.
6. The method of claim 2, wherein, The method further comprises: When it is determined according to the connection result that the M communication ports all fail to connect with the first process, connection between the M communication ports and the first process is established again; When it is determined again according to the re-acquired connection result that the M communication ports all fail to connect with the first process, the first process is taken as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP; From the N-M communication ports that successfully bind, a communication port is selected as a target communication port, and connection between the target communication port and the first process is established.
7. The method of claim 1, wherein, The method further comprises: When cross-process communication is performed between two client-used second processes, the first process is controlled to receive a request data packet through the target communication port; the request data packet is sent by a second process used by the two clients and serving as a request side of cross-process communication, and the request data packet comprises process identifier information of a second process serving as a receiving side of cross-process communication and request information; The first process is controlled to send the request data packet to the second process serving as the receiving side of cross-process communication through the target communication port, so as to realize cross-process communication between the two client-used second processes.
8. The method of claim 1 or 6, wherein, The method further comprises: When it is determined that the first process is disconnected from the communication port, a target second process that starts cross-process communication service earliest is selected from the at least one second process as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP, and a new target communication port is determined; The target second process performs communication with each second process except the target second process through the new target communication port when performing cross-process communication.
9. The method of any one of claims 2-5, wherein, The method further comprises: When it is determined that the third process is disconnected from the communication port, a target first process that starts cross-process communication service earliest is selected from at least one first process associated with cross-process communication service as a server of cross-process communication based on UDP and a server of cross-process communication based on TCP, and a new target communication port is determined; Each first process associated with cross-process communication service except the target first process is taken as a client of cross-process communication, and connection with the new target communication port is established respectively; When performing cross-process communication, each first process except the target first process performs communication with the target first process through the new target communication port.
10. The method of claim 8, wherein, The disconnection of the first process from the communication port is determined in the following manner: When the first process does not receive a data packet or a heartbeat packet within a set time interval, causing the first process to close cross-process communication service, it is determined that the target communication port is disconnected; Or, When the first process ends, it is determined that the first process is disconnected from the target communication port.
11. A cross-process communication device, comprising: The method comprises the steps of: obtaining a pre-binding result between N communication ports of an operating system and the first process when the first process requests to perform cross-process communication; determining, based on the pre-binding result, that the first process is a server for cross-process communication based on user datagram protocol (UDP) when it is determined that the N communication ports are all successfully pre-bound with the first process, and that the first process is a server for cross-process communication based on transmission control protocol (TCP); selecting one of the N communication ports as a target communication port, and establishing a connection between the target communication port and the first process, so that the first process communicates with at least one second process used by a client associated with the cross-process communication through the target communication port, wherein each of the second processes uses UDP or TCP to perform cross-process communication with the first process.
12. An electronic device, comprising: The method comprises the steps of: a memory and a processor; the memory is configured to store computer instructions; the processor is configured to obtain the computer instructions stored in the memory, and execute the method according to any one of claims 1-10 according to the computer instructions.
13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, and when the computer instructions are executed by the processor, the method according to any one of claims 1-10 is implemented.