Communication method between applications, terminal device and storage medium
A communication method and technology of terminal equipment, applied in the field of communication, can solve the problems of long communication development cycle and poor stability, and achieve the effect of shortening the development cycle and good communication stability
Active Publication Date: 2018-12-18
PAX COMP TECH SHENZHEN
5 Cites 3 Cited by
AI-Extracted Technical Summary
Problems solved by technology
[0004] In view of this, the embodiment of the present application provides a communication method between applications, a terminal device, and a compu...
Abstract
The present application is applicable to the field of communication technology, a method of communication between applications, a terminal device and a computer readable storage media are provided. The method comprises: the first application establishes a connection with the server based on an interface provided by the first client, the second application establishes a connection with the serverbased on an interface provided by the second client, As such, a communication connection is established between that first application and the second application, the first application then sends a first communication message to the second application through the communication connection, the second application may return a second communication message to the first application through the communication connection, after the communication connection between the first application and the second application is completed, the communication connection between the first application and the second application is disconnected by the release request, and since the interface provided by the client has information for converting the data of the application to conform to the communication protocol. The communication method development period between the applications is short and the stability is good.
Application Domain
Transmission
Technology Topic
Data AppliedTerminal equipment +2
Image
Examples
- Experimental program(1)
Example Embodiment
[0027] In the following description, for the purpose of illustration rather than limitation, specific details such as a specific system structure and technology are proposed for a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from obstructing the description of this application.
[0028] It should be understood that when used in this specification and appended claims, the term "comprising" indicates the existence of the described features, wholes, steps, operations, elements, and/or components, but does not exclude one or more other features The existence or addition of, whole, step, operation, element, component and/or its collection.
[0029] It should also be understood that the terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in the specification of this application and the appended claims, unless the context clearly indicates other circumstances, the singular forms "a", "an" and "the" are intended to include plural forms.
[0030] It should be further understood that the term "and/or" used in the specification and appended claims of this application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations .
[0031] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "once" or "in response to determination" or "in response to detection" depending on the context . Similarly, the phrase "if determined" or "if detected [described condition or event]" can be interpreted as meaning "once determined" or "in response to determination" or "once detected [described condition or event]" depending on the context ]" or "in response to detection of [condition or event described]".
[0032] In order to explain the technical solution described in this application, firstly describe the system architecture in this application, such as figure 1 As shown, figure 1 In the system architecture provided by the embodiments of this application, it can be seen from the figure that application A and application B are located in the same terminal device (for example, POS machine), and application A and application C are located in different terminal devices (for example, located in POS machine and In the cash register), the communication between applications in the embodiments of this application can be the communication between application A and application B, or the communication between application A and application C, that is, one of the applications in the embodiments of this application Inter-communication does not limit whether the application is in the same terminal device. The data flow represented by the dotted line in the figure is the intended data flow to be realized, and the data flow represented by the realization in the figure is the actual data flow that actually occurs. Application A, Application B, and Application C communicate with the server through the interface provided by the corresponding client.
[0033] The following uses specific embodiments to illustrate. It should be noted that the embodiments of this application are described from the server side. In order to clearly describe the timing process of communication between applications, the application or the client side of the application will also be described. Side to explain.
[0034] figure 2 It is a schematic diagram of the implementation process of a communication method between applications provided by an embodiment of the present application. As shown in the figure, the method may include the following steps:
[0035] Step S201: Receive a registration request sent by a first client corresponding to a first application, and set a unique identifier for the first application based on the registration request.
[0036] In the embodiment of the present application, the registration request is information conforming to the communication protocol obtained by the first client according to the initialization information of the first application.
[0037] In order to more clearly illustrate the steps in the embodiments of this application, you can combine image 3 The timing diagram of communication between applications is shown to assist in explanation,
[0038] To image 3 As an example, the communication service is the service provided by the server. The first application establishes a communication connection with the server through the interface provided by the first client corresponding to the first application, and the second application provides the service through the second client corresponding to the second application. The interface establishes a communication connection with the server. Both the first client and the second client have the function of converting application data into information conforming to a specific communication protocol.
[0039] When communication between the first application and the second application is required, first ensure that both the first application and the second application are applications registered on the server. We take the first application as an example to describe the registration process. First, The first application sends initialization information to the interface provided by the first client. The interface provided by the first client has the function of transforming the data of the first application into information conforming to a specific communication protocol, so the initialization of the first application can be indirectly The information is transformed into a registration request. The first client sends the registration request to the server. After receiving the registration request sent by the first client, the server needs to be the first client corresponding to the first client based on the registration request. The application sets a unique identifier, and also wants the first client to return a registration response.
[0040] The registration request includes: the communication mode and communication parameters of the client; in this way, the server will save the communication mode and communication parameters of the application. In actual applications, it may also include: communication handle, session ID, status (idle, busy, abnormal) And other information.
[0041] Step S202: Receive a handshake request sent by the first client, and send a connection request conforming to the communication protocol to a second client corresponding to the second application based on the handshake request, the second application being registered with the server Applications.
[0042] In the embodiment of the present application, the handshake request is information conforming to the communication protocol obtained by the first client according to the link establishment information sent by the first application, and the connection request is used to instruct the second client The terminal sends a link establishment notification to the second application according to the connection request. When a registered application needs to communicate with other registered applications, it can send link establishment information to the corresponding client. Taking the first application as an example, the first application sends link establishment information to the first client. The client converts the link establishment information into a handshake request conforming to the communication protocol, and the second client sends the handshake request to the server. It should be noted that after the server ends the handshake request, the handshake request includes For connected applications, this embodiment of the application takes the second application as an example. First, it is necessary to confirm whether the second application in the handshake request sent by the first client is in an idle state; if the second application is in an idle state, establish The communication between the first application corresponding to the first client and the second application corresponding to the second client is realized based on the threads of the first client and the second client, and based on the threads. The server sends a connection request to the second client according to the current thread, and the second client converts the connection request conforming to the communication protocol into a link establishment notification that the second application can recognize. Of course, the second client receives the connection After the request, it will return a connection response to the server, and the server will return a handshake response to the first client after receiving the connection response sent by the second client.
[0043] Step S203: Receive the first communication message sent by the first client, and forward the first communication message to the second client.
[0044] In the embodiment of the present application, the first communication message is information conforming to the communication protocol obtained by the first client according to the first data sent by the first application, and the first communication message is used for Instruct the second client to convert the first communication message into the first data and then send the first data to the second application. The first application can send the first data to the second application to the first client At the end, the first client converts the first data into a first communication message conforming to the communication protocol, and then sends the first communication message to the server. It should be noted here that after the server receives the first communication message , Will analyze and verify the validity of the first communication message; if the first communication message is valid, the first communication message is forwarded to the second client. The second client also needs to convert the second communication message into first data that can be recognized by the second application, and then send the first data to the second application.
[0045] Since the first application and the second application may exist in the same terminal device or different terminal devices, it is also necessary for the server to receive the first communication message sent by the first client based on the first communication message. The communication mode and communication parameters of a client start the communication mode supported by the first client, and then receive the first communication message sent by the first client based on the communication mode supported by the first client; Before the first communication message is forwarded to the second client, it is also necessary to start the communication mode supported by the second client based on the communication mode and communication parameters of the second client, and then based on the second client The communication method supported by the client forwards the first communication message to the second client.
[0046] In addition, when the first application and the second application are located in the same terminal device, the communication mode between the first client and the server is a local socket mode, and the communication mode between the second client and the server is Local socket mode;
[0047] When the first application and the second application are not located in the same terminal device, at least one of the first client and the second client communicates with the server in a manner other than a local socket. Non-local socket methods include: serial port, USB, network, etc.
[0048] Step S204: Receive a second communication message returned by the second client, and return the second communication message to the first client.
[0049] In the embodiment of the present application, the second communication message is information conforming to the communication protocol obtained by the second client according to the second data returned by the second application, and the second communication message is used for Instruct the first client to convert the second communication message into second data and send the second data to the first application. After receiving the first data, the second application can return the second data to the second The client, after receiving the second data, the second client can convert the second data into a second communication message conforming to the communication protocol, and send the second communication message to the server, and the server receives the second After the communication message, the second communication message is returned to the first client. The first client converts the second communication message into second data that can be recognized by the first application, and sends the second data to the first application .
[0050] It should be noted that after receiving the second communication message, the server can also analyze and verify the validity of the second communication message; if the second communication message is valid, the second communication message The message is forwarded to the first client.
[0051] Step S205: Receive a release request sent by the first client, and send a release notification to the second client based on the release request.
[0052] In the embodiment of the present application, the release request is information conforming to the communication protocol obtained by the first client according to the link disconnection information sent by the first application, and the release notification is used to instruct the second client to After the release notification is converted into a link disconnection notification, the link disconnection notification is sent to the second application, image 3 Only shows the communication process of a communication message between the first application and the second application. In fact, it can be carried out multiple times. When the first application and the second application terminate the communication, the first application can send a message to the first client The first client sends the disconnection information, and the first client converts the first disconnection information into a release request conforming to the communication protocol, and sends the release request to the server. The server first sends a release notification to the second client according to the release request. The second client converts the release notification into a link disconnection notification conforming to the communication protocol, and sends the link disconnection notification to the second application.
[0053] As another embodiment of the present application, after receiving the information sent by the first client or the second client, the server further includes:
[0054] Return response information to the first client or second client corresponding to the message, where the response information is used to indicate that the message has arrived;
[0055] The message sent by the first client includes: a registration request, a handshake request, a first communication message, and a release request;
[0056] The message sent by the second client includes: a second communication message.
[0057] In the examples of this application, image 3 It can be seen that the data communication between the server and the first client will both return corresponding response information. Similarly, the data communication between the server and the second client will also return corresponding response information.
[0058] As another embodiment of the present application, before receiving the release request sent by the first client, if the handshake request sent by the third client corresponding to the third application is received, the method further includes:
[0059] Confirming whether the fourth application in the handshake request sent by the third client is in an idle state, and the third application and the fourth application are applications registered on the server;
[0060] If the fourth application is in an idle state, a thread based on the third client and the fourth client is established, and the third application corresponding to the third client and the fourth client corresponding to the third client are implemented based on the thread Communication between the fourth application.
[0061] In the embodiments of this application, an application can only communicate with another application at a time, and cannot communicate with multiple applications at the same time. However, the server can implement communication between multiple sets of applications at the same time, for example, the first application can be implemented at the same time. Communication with the second application, communication between the third application and the fourth application. In this way, the first thread can be occupied between the first application and the second application, and the second thread can be occupied by the third application and the fourth application before, that is, the embodiment of the present application supports multiple concurrent communication processes.
[0062] In order to explain the embodiments of this application more clearly, some communication protocols are listed
[0063] Table 1 Serial data exchange communication structure
[0064]
[0065] Table 2 Network data exchange communication structure
[0066]
[0067] Table 3 shows the meaning of the symbols in Table 1 or Table 2
[0068]
[0069]
[0070] Table 4 Configuration file parameters (when setting the communication mode, it can be set according to the configuration file)
[0071]
[0072] Table 5 Registration Request
[0073]
[0074]
[0075] Table 6 Response information of registration request
[0076] domain name
[0077] Table 7 Handshake request
[0078] domain name
[0079] Table 8 Response information of handshake request
[0080] domain name
[0081] Table 9 sends communication messages:
[0082]
[0083]
[0084] Table 10 Response information corresponding to the sent communication message
[0085] domain name
[0086] Table 11 Receive communication message
[0087]
[0088] Table 12 Response information corresponding to the received communication message
[0089] domain name
[0090] Table 13 Release request
[0091]
[0092]
[0093] Table 14 Response information corresponding to the release request
[0094] domain name
[0095] It should be understood that the size of the sequence number of each step in the foregoing embodiment does not mean the order of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0096] Figure 4 It is a schematic block diagram of a terminal device provided in an embodiment of the present application. For ease of description, only parts related to the embodiment of the present application are shown.
[0097] The terminal device 4 can be a software unit, a hardware unit, or a combination of software and hardware built into terminal devices such as mobile phones, tablet computers, notebooks, computers, etc., or can be integrated into the mobile phones, tablet computers, notebooks, etc. as independent pendants. In terminal equipment such as computers.
[0098] The terminal device 4 includes:
[0099] The registration module 41 is configured to receive a registration request sent by a first client corresponding to a first application, and set a unique identifier for the first application corresponding to the first client based on the registration request;
[0100] The handshake module 42 is configured to receive a handshake request sent by the first client, and based on the handshake request, send a connection request conforming to the communication protocol to a second client corresponding to the second application, where the second application is in the service Applications registered at the end;
[0101] The first communication module 43 is configured to receive a first communication message sent by a first client, and forward the first communication message to the second client;
[0102] The second communication module 44 is configured to receive a second communication message returned by the second client, and return the second communication message to the first client;
[0103] The release module 45 is configured to receive a release request sent by the first client, and send a release notification to the second client based on the release request.
[0104] Optionally, the registration request is information conforming to the communication protocol obtained by the first client according to the initialization information of the first application;
[0105] The handshake request is information conforming to the communication protocol obtained by the first client according to the link establishment information sent by the first application, and the connection request is used for instructing the second client to send the message according to the connection request The second application sends a link establishment notification;
[0106] The first communication message is information conforming to the communication protocol obtained by the first client according to the first data sent by the first application, and the first communication message is used to instruct the second client Sending the first data to the second application after the first communication message is converted into the first data;
[0107] The second communication message is information conforming to the communication protocol obtained by the second client according to the second data returned by the second application, and the second communication message is used to instruct the first client After the second communication message is converted into second data, the second data is sent to the first application;
[0108] The release request is information conforming to the communication protocol obtained by the first client according to the link disconnection information sent by the first application, and the release notification is used to instruct the second client to convert the release notification into a disconnection. After the link notification, the link disconnection notification is sent to the second application.
[0109] Optionally, the registration request includes: the communication mode and communication parameters of the client;
[0110] Correspondingly, the first communication module 43 is also used for:
[0111] Starting the communication mode supported by the first client based on the communication mode and communication parameters of the first client, and receiving a first communication message sent by the first client based on the communication mode supported by the first client;
[0112] Start the communication mode supported by the second client based on the communication mode and communication parameters of the second client, and forward the first communication message to the second client based on the communication mode supported by the second client Client.
[0113] Optionally, the first communication module 43 is further configured to:
[0114] Before forwarding the first communication message to the second client, parsing and verifying the validity of the first communication message;
[0115] If the first communication message is valid, forward the first communication message to the second client.
[0116] Optionally, the handshake module 42 is also used to:
[0117] Confirming whether the second application in the handshake request sent by the first client is in an idle state;
[0118] If the second application is in an idle state, a thread based on the first client and the second client is established, and the first application corresponding to the first client and the second client are corresponding to each other based on the thread. Communication between the second application.
[0119] Optionally, the terminal device 4 further includes:
[0120] The third communication module is configured to, before receiving the release request sent by the first client, if the handshake request sent by the third client corresponding to the third application is received, confirm the first in the handshake request sent by the third client 4. Whether the application is in an idle state, and the third application and the fourth application are applications registered on the server;
[0121] If the fourth application is in an idle state, a thread based on the third client and the fourth client is established, and the third application corresponding to the third client and the fourth client corresponding to the third client are implemented based on the thread Communication between the fourth application.
[0122] Optionally, when the first application and the second application are located in the same terminal device, the communication mode between the first client and the server is a local socket mode, and the communication between the second client and the server is The communication method is local socket;
[0123] When the first application and the second application are not located in the same terminal device, at least one of the first client and the second client communicates with the server in a manner other than a local socket.
[0124] Optionally, the terminal device 4 further includes:
[0125] The response module is used to return response information to the first client or second client corresponding to the message after receiving the information sent by the first client or the second client. The response information is used to indicate that the message has been Arrivals;
[0126] The message sent by the first client includes: a registration request, a handshake request, a first communication message, and a release request;
[0127] The message sent by the second client includes: a second communication message.
[0128] Those skilled in the art can clearly understand that for the convenience and conciseness of the description, only the division of the above-mentioned functional units and modules is used as an example. In practical applications, the above-mentioned functions can be allocated to different functional units and modules as required. Module completion, that is, the internal structure of the terminal device is divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist alone physically, or two or more units can be integrated into one unit. The above-mentioned integrated units can be hardware-based Form realization can also be realized in the form of software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the present application. For the specific working process of the units and modules in the above-mentioned device, reference may be made to the corresponding process in the foregoing method embodiment, which will not be repeated here.
[0129] Figure 5 It is a schematic block diagram of a terminal device provided by another embodiment of the present application. Such as Figure 5 As shown, the terminal device 5 of this embodiment includes: one or more processors 50, a memory 51, and a computer program 52 stored in the memory 51 and running on the processor 50. When the processor 50 executes the computer program 52, the steps in the above embodiments of the camera control method are implemented, for example figure 2 Steps S201 to S205 are shown. Alternatively, when the processor 50 executes the computer program 52, the function of each module/unit in the foregoing terminal device embodiment is realized, for example Figure 4 The functions of modules 41 to 45 are shown.
[0130] Exemplarily, the computer program 52 may be divided into one or more modules/units, and the one or more modules/units are stored in the memory 51 and executed by the processor 50 to complete This application. The one or more modules/units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 52 in the terminal device 5. For example, the computer program 52 may be divided into a registration module, a handshake module, a first communication module, a second communication module, and a release module.
[0131] A registration module, configured to receive a registration request sent by a first client corresponding to a first application, and set a unique identifier for the first application corresponding to the first client based on the registration request;
[0132] The handshake module is configured to receive the handshake request sent by the first client, and send a connection request conforming to the communication protocol to the second client corresponding to the second application based on the handshake request, where the second application is on the server Registered applications;
[0133] The first communication module is configured to receive a first communication message sent by a first client, and forward the first communication message to the second client;
[0134] The second communication module is configured to receive the second communication message returned by the second client, and return the second communication message to the first client;
[0135] The release module is configured to receive a release request sent by the first client, and send a release notification to the second client based on the release request.
[0136] Other modules can refer to Figure 4 The description in the illustrated embodiment will not be repeated here.
[0137] The terminal device includes but is not limited to a processor 50 and a memory 51. Those skilled in the art can understand, Figure 5 It is only an example of the terminal device 5, and does not constitute a limitation on the terminal device 5. It may include more or fewer components than shown in the figure, or some components may be combined, or different components, for example, the terminal device may also Including input devices, output devices, network access devices, buses, etc.
[0138] The processor 50 may be a central processing unit (Central Processing Unit, CPU), other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), Ready-made programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like.
[0139] The memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or a memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5, for example, a plug-in hard disk equipped on the terminal device 5, a smart memory card (Smart Media Card, SMC), and a Secure Digital (SD). Card, Flash Card, etc. Further, the memory 51 may also include both an internal storage unit of the terminal device 5 and an external storage device. The memory 51 is used to store the computer program and other programs and data required by the terminal device. The memory 51 can also be used to temporarily store data that has been output or will be output.
[0140] In the above-mentioned embodiments, the description of each embodiment has its own focus. For parts that are not detailed or recorded in an embodiment, reference may be made to related descriptions of other embodiments.
[0141] A person of ordinary skill in the art may realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of this application.
[0142] In the embodiments provided in this application, it should be understood that the disclosed terminal device and method may be implemented in other ways. For example, the terminal device embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components. Can be combined or integrated into another system, or some features can be omitted or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
[0143] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
[0144] In addition, the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit can be realized in the form of hardware or software functional unit.
[0145] If the integrated module/unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, this application implements all or part of the processes in the above-mentioned embodiments and methods, and can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the program is executed by the processor, it can implement the steps of the foregoing method embodiments. Wherein, the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file, or some intermediate forms. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory) , Random Access Memory (RAM, Random Access Memory), electrical carrier signal, telecommunications signal, and software distribution media. It should be noted that the content contained in the computer-readable medium can be appropriately added or deleted according to the requirements of the legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to the legislation and patent practice, the computer-readable medium Does not include electrical carrier signals and telecommunication signals.
[0146] The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still implement the foregoing The technical solutions recorded in the examples are modified, or some of the technical features are equivalently replaced; these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the application, and should be included in Within the scope of protection of this application.
PUM


Description & Claims & Application Information
We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.
Similar technology patents
Method and system for dynamically inserting data mining algorithm into data mining platform
Owner:KARAMAY HONGYOU SOFTWARE
Rapid densifying method for powder high-temperature alloy component
Owner:AVIC BEIJING INST OF AERONAUTICAL MATERIALS
Testing device for integrated circuit board
Owner:GOERTEK INC
Device for verifying advanced microcontroller bus interface
Owner:GUANGDONG NUFRONT COMP SYST CHIP
Classification and recommendation of technical efficacy words
- Shorten the development cycle
Flight simulation system with high instantaneity
Owner:BEIHANG UNIV
Embedded system firmware on-line upgrading system
Owner:HANGZHOU HIKVISION DIGITAL TECH
Method for realizing web crawler tasks
Owner:维我软件(上海)有限公司