A kind of method and device of communicationTechnical field
This specification one or more embodiment is related to the method and dress of field of computer technology more particularly to a kind of communicationIt sets.
Background technique
Currently, in a local network, technical staff generallys use Socket.IO to realize the two-way communication between terminal.
However, being based on Socket.IO, the two-way communication of point-to-point can only be carried out between terminal, can not be carried out point-to-multipointTwo-way communication.
It would therefore be highly desirable to a kind of scheme for realizing two-way communication point-to-multipoint between terminal.
Summary of the invention
This specification one or more embodiment describes a kind of method and device of communication, can be realized point between terminalTo the two-way communication of multiple spot.
In a first aspect, providing a kind of method of communication, the method is applied to first terminal, and the first terminal includesContainer with agent functionality, the container correspond to multiple application programs in multiple terminals, the multiple terminal packetInclude the first terminal, which comprises
The first application program by establishing connection in the multiple application program of the container reception with the container is sent outThe posting request sent carries message and the corresponding first message of the message to be released to be released in the posting requestTheme, first application program are the application program in application program or other terminals in the first terminal;
According to the subscribing relationship of application program and message subject pre-stored in the container, the multiple application is determinedThe second application program of the first message theme is subscribed in program;
The message is sent to terminal belonging to second application program by the container.
Optionally, the method also includes:
The subscription request sent by third application program in the multiple application program of the container reception, the subscriptionSecond message theme is carried in request;
In the above-described container in pre-stored application program and the subscribing relationship of message subject, the third application is addedThe subscribing relationship of program and the second message theme.
Optionally, the method also includes establishing connection by the container and first application program, comprising:
By the connection request of the transmission of the first application program described in the container reception, carries and add in the connection requestFirst password after close, the encrypted first password are that first application program is close to described first by the first private keyWhat code obtained after being encrypted;
According to the corresponding public key of first private key pre-stored in the container to the encrypted first passwordIt is decrypted, obtains the first password;
According to the corresponding relationship of application program and password pre-stored in the container, first application program is determinedCorresponding second password;
If the first password is identical as second password, sent out by the container to first application programSuccessful connection is sent to respond, so that first application program and the container establish connection;
If the first password is different from second password, sent out by the container to first application programConnection failure is sent to respond.
Optionally, the method also includes:
The password acquisition request sent by the first application program described in the container reception;
The corresponding third password of first application program is obtained by container;
The third password is encrypted according to the second private key pre-stored in the container, obtains encryptedThree passwords;
Password is sent to first application program by the container and obtains response, and the password obtains to be carried in responseThere is the encrypted third password.
It is optionally, described to obtain the corresponding third password of first application program, comprising:
According to the corresponding relationship of application program and password pre-stored in the container, first application program is determinedCorresponding third password.
It is optionally, described to obtain the corresponding third password of first application program, comprising:
According to preset password create-rule, the corresponding third password of first application program is generated;
The method also includes:
The corresponding relationship of first application program and the third password is stored into the container.
Second aspect provides a kind of device of communication, and described device is deployed in first terminal and has agent functionality,Described device corresponds to multiple application programs in multiple terminals, and the multiple terminal includes the first terminal, describedDevice includes:
First receiving module, for receiving in the multiple application program establish connection with described device first using journeyThe posting request that sequence is sent carries message and the message to be released corresponding first to be released in the posting requestMessage subject, first application program are the application program in application program or other terminals in the first terminal;
First determining module, for the subscribing relationship of application program according to the pre-stored data and message subject, determine described inThe second application program of the first message theme is subscribed in multiple application programs;
First sending module, for sending the message to terminal belonging to second application program.
Optionally, described device further include:
Second receiving module, for receiving the subscription request that third application program is sent in the multiple application program, instituteIt states in subscription request and carries second message theme;
Adding module, for adding the third in the subscribing relationship of pre-stored application program and message subjectThe subscribing relationship of application program and the second message theme.
Optionally, described device further include:
Third receiving module is taken in the connection request for receiving the connection request of the first application program transmissionWith encrypted first password, the encrypted first password is that first application program passes through the first private key to describedWhat first password obtained after being encrypted;
It is close to described encrypted first to be used for the corresponding public key of first private key according to the pre-stored data for deciphering moduleCode is decrypted, and obtains the first password;
Second determining module determines described first for the corresponding relationship of application program according to the pre-stored data and passwordCorresponding second password of application program;
Second sending module, if identical as second password for the first password, to first applicationProgram sends successful connection response, so that first application program and the container establish connection;
Third sending module, if different from second password for the first password, to first applicationProgram sends connection failure response.
Optionally, described device further include:
4th receiving module, the password acquisition request sent for receiving first application program;
Module is obtained, for obtaining the corresponding third password of first application program;
Encrypting module encrypts the third password for the second private key according to the pre-stored data, after obtaining encryptionThird password;
4th sending module obtains response for sending password to first application program, and the password obtains responseIn carry the encrypted third password.
Optionally, the acquisition module, is specifically used for:
According to the corresponding relationship of application program and password pre-stored in the container, first application program is determinedCorresponding third password.
Optionally, the acquisition module, is specifically used for:
According to preset password create-rule, the corresponding third password of first application program is generated;
Described device further include:
Memory module, for storing the corresponding relationship of first application program and the third password to described deviceIn.
The third aspect provides a kind of terminal, including memory and processor, is stored with executable generation in the memoryCode when the processor executes the executable code, realizes the method for any one of first aspect.
Fourth aspect provides a kind of computer readable storage medium, is stored thereon with computer program, wherein works as instituteWhen stating computer program and executing in a computer, computer is enabled to execute the method for any one of first aspect.
By a kind of method and device for communication that this specification embodiment provides, first terminal is multiple by container receptionThe posting request that the first application program of connection is sent is established in application program with container.Wherein, carried in posting request toThe message of publication and the corresponding first message theme of message to be released.Then, first terminal is according to pre-stored in containerThe subscribing relationship of application program and message subject determines that the second of first message theme is subscribed in multiple application programs applies journeySequence, and message is sent to terminal belonging to the second application program by container.In this way, when the first container receives in first terminalThe first application issued to the message of first message theme after, can be to subscribing to all second answering for the first message themeThe terminal belonging to program forwards the message, to realize communication point-to-multipoint between first terminal and other terminals.
Detailed description of the invention
In order to illustrate the technical solution of the embodiments of the present invention more clearly, required use in being described below to embodimentAttached drawing be briefly described, it should be apparent that, drawings in the following description are only some embodiments of the invention, for thisFor the those of ordinary skill of field, without creative efforts, it can also be obtained according to these attached drawings othersAttached drawing.
Fig. 1 is the architecture diagram for the system that this specification embodiment provides;
Fig. 2 is a kind of flow chart of the method for communication that this specification embodiment provides;
Fig. 3 is a kind of structural schematic diagram of the device for communication that this specification embodiment provides.
Specific embodiment
With reference to the accompanying drawing, the scheme provided this specification is described.
Fig. 1 is the architecture diagram for the system that this specification embodiment provides, as shown in Figure 1, the system may include mutually interconnectingThe first terminal and second terminal connect.The first application and the second application have been separately operable in first terminal and second terminal.Wherein,First application and the second application can be mixed mode mobile application (hybrid-app) or web app (web-) or native applications (native-app) app.First application may include the first application program and the first container.This secondUsing may include the second application program and second container.Wherein, it is integrated with and orders in the first application program and the second application programRead (Subscribers) function and publication (Publishers) function;Agency is integrated in the first container or the second container(broker) function and security function.The embodiment of the present application for being integrated with agent functionality and security function in the first container intoRow is introduced, other situations are similar therewith.
It should be noted that the agency integrated in the subscription function and issuing function and container that are integrated in application programMessage queue telemetering transport protocol (Message Queuing Telemetry may be implemented in function and security functionTransport, MQTT) or WebSocket agreement in subscription function, issuing function, agent functionality and security function, can alsoThink that subscription function, issuing function, agent functionality and the security function in other kinds of agreement, the embodiment of the present application do not limitIt is fixed.
This specification embodiment provides a kind of method of communication, and two-way point-to-multipoint between terminal may be implementedLetter, this method is applied to first terminal, as shown in Fig. 2, treatment process is as follows:
Step 201, journey is applied by establishing the first of connection in the multiple application program of container reception with the containerThe posting request that sequence is sent.
Wherein, message to be released and the corresponding first message theme of message to be released are carried in posting request.
In an implementation, when first terminal needs are communicated with other terminals, first terminal can be by being mounted on thisIn first terminal first application comprising application program (i.e. the first application program) and this first application comprising have agencyThe container (i.e. the first container) of function establishes connection.Then, first terminal can by first application program to this first holdDevice sends posting request.Wherein, message to be released and the corresponding first message of message to be released are carried in posting requestTheme.After the first container receives the posting request of the first application program transmission, which can be parsed, be obtainedThe message to be released carried in the posting request and the corresponding first message theme of message to be released.
It should be noted that the first application program can be the first application program in first terminal, or otherApplication program in terminal.The embodiment of the present application is carried out so that the first application program is the first application program in first terminal as an exampleIt introduces, other situations are similar therewith.
Step 202, according to the subscribing relationship of application program and message subject pre-stored in container, multiple applications are determinedThe second application program of first message theme is subscribed in program.
In an implementation, the subscribing relationship of application program and message subject can be previously stored in the first container.The subscriptionRelationship can be configured by technical staff, and the subscription request that can also be sent according to application program is established.The first containerIt obtains the message to be released carried in the posting request of the first application program transmission and message corresponding first to be released disappearsAfter ceasing theme, it can inquire in multiple application programs and order in pre-stored application program and the subscribing relationship of message subjectRead the second application program of the first message theme.
Step 203, message is sent to terminal belonging to the second application program by container.
In an implementation, after the first container obtains the second application program of subscription first message theme, which can be turnedIt is sent to terminal belonging to second application program.In this way, when the first container receives the hair of the first application program in first terminalIt, can be to terminal belonging to all second application programs for subscribing to the first message theme after cloth to the message of first message themeThe message is forwarded, to realize communication point-to-multipoint between first terminal and other terminals.
Optionally, the subscription that first terminal can also be sent according to the first application program is requested, and is established application program and is disappearedThe subscribing relationship of theme is ceased, detailed process is as follows:
Step 1 is requested by the subscription that third application program in the multiple application programs of container reception is sent.
Wherein, it subscribes in request and carries second message theme.
In an implementation, third application program can be the application program in first terminal, or in other terminalsApplication program.The embodiment of the present application is introduced by taking the first application program in first terminal as an example, other situations are similar therewith.When first terminal needs to subscribe to a certain message subject, first terminal can be applied by first be mounted in the first terminalThe first application program for including to first application comprising the first container with agent functionality send to subscribe to and request.Wherein,Second message theme is carried in subscription request.It, can after the first container receives the subscription request of the first application program transmissionTo parse to subscription request, the second message theme carried in subscription request is obtained.
Step 2 in a reservoir in pre-stored application program and the subscribing relationship of message subject, adds third applicationThe subscribing relationship of program and second message theme.
In an implementation, the first container obtains the second message theme carried in the subscription request of the first application program transmissionAfterwards, the first application program and second message can be added in pre-stored application program and the subscribing relationship of message subjectThe subscribing relationship of theme.In this way, being distributed to second message master when the first container receives terminal belonging to other applicationsWhen the message of topic, it can send the message to first according to the subscribing relationship of the first application program and second message theme and answerThe first terminal belonging to program.
Optionally, the connection request that first terminal can also be sent according to the first application program, establishes the first application programWith the connection of the first container.Detailed process is as follows:
Step 1, the connection request sent by the first application program of container reception.
Wherein, encrypted first password is carried in connection request, encrypted first password is the first application programIt is obtained after being encrypted by the first private key to first password.
In an implementation, when first terminal needs are communicated with other terminals, first terminal needs to answer first firstConnection is established with program and the first container.The first terminal can by be mounted in the first terminal first application comprisingFirst application program to this first application comprising with agent functionality the first container transmission connection request.Wherein, the connectionEncrypted first password is carried in request, the encrypted first password be the first application program by the first private key to theWhat one password obtained after being encrypted.It, can be to the company after the first container receives the connection request of the first application program transmissionIt connects request to be parsed, obtains the encrypted first password carried in the connection request.
It should be noted that the encrypted first password can be used as the uniform resource identifier in connection requestThe parameter of (Uniform Resource Identifier, URI) is transmitted.
Step 2 solves encrypted first password according to the corresponding public key of the first private key pre-stored in containerIt is close, obtain first password.
In an implementation, it is close to obtain carry in the connection request of the first application program transmission encrypted first for the first containerAfter code, the encrypted first password can be decrypted with the corresponding public key of the first private key according to the pre-stored data, obtain theOne password.
Step 3 determines the first application program according to the corresponding relationship of application program and password pre-stored in containerCorresponding second password.
In an implementation, the corresponding relationship of application program and password can also be previously stored in the first container.This applies journeyThe corresponding password of sequence can be configured by technical staff, can also be generated according to preset password create-rule.The first containerIt, can be in the corresponding relationship of pre-stored application program and password after the connection request for receiving the transmission of the first application programIn, inquire corresponding second password of first application program.It, can be into one after the first container obtains first password and the second passwordStep judges whether first password and the second password are identical.If first password is identical as the second password, four are thened follow the steps.IfFirst password is different from the second password, thens follow the steps five.
Step 4 sends successful connection response to the first application program by container, so that the first application program and containerEstablish connection.
In an implementation, if first password is identical as the second password, illustrate that the first container tests the first application programIt demonstrate,proves successfully, the first container can send successful connection response to the first application program.In this way, the first application program receives firstAfter the successful connection response that container is sent, connection can be established with the first container.
Step 5 sends connection failure response to the first application program by container.
In an implementation, if first password is different from the second password, illustrate that the first container tests the first application programCard failure, the first container can send connection failure response to the first application program.
Optionally, the password acquisition request that first terminal can also be sent according to the first application program obtains the first applicationThe corresponding password of program.Detailed process is as follows:
Step 1, the password acquisition request sent by the first application program of container reception.
In an implementation, when first terminal needs to establish the connection of the first application program and the first container, the first terminalCan by be mounted in the first terminal first application comprising the first application program to this first application comprising haveThe first container of agent functionality sends password acquisition request.
Step 2 obtains the corresponding third password of the first application program by container.
In an implementation, after the first container receives the password acquisition request of the first application program transmission, it is available thisThe corresponding third password of one application program.Wherein, the first container obtains the mode of the corresponding third password of first application programIt can be diversified, the embodiment of the present application provides two kinds of feasible embodiments.
Embodiment one determines the first application according to the corresponding relationship of application program and password pre-stored in containerThe corresponding third password of program.
In an implementation, the corresponding relationship of application program and password can be previously stored in the first container, the corresponding relationshipIt can be configured by technical staff.After the first container receives the password acquisition request of the first application program transmission, Ke YiIn the corresponding relationship of pre-stored application program and password, the corresponding third password of first application program is inquired.
Embodiment two generates the corresponding third password of the first application program according to preset password create-rule.
In an implementation, password create-rule can be previously stored in the first container.The password create-rule can be by skillArt personnel are configured.It, can be according to preset after the first container receives the password acquisition request of the first application program transmissionPassword create-rule generates the corresponding third password of the first application program.
Optionally, the first container generates the corresponding third password of the first application program according to preset password create-ruleAfterwards, the corresponding relationship of the first application program and third password can also be stored into container, applies journey to first so as to subsequentSequence is verified.
Step 3 encrypts third password according to the second private key pre-stored in container, obtains encryptedThree passwords.
It in an implementation, can be according to the pre-stored data after the first container obtains the corresponding third password of the first application programSecond private key encrypts third password, obtains encrypted third password.
Step 4 sends password to the first application program by container and obtains response.
Wherein, password obtains in response and carries encrypted third password.
In an implementation, after the first container obtains encrypted third password, password can be sent to the first application program and obtainedTake response.Wherein, password obtains in response and carries encrypted third password.Subsequent, the first application program receives firstAfter the password of container transmission obtains response, response can be obtained to the password and parsed, obtain taking in password acquisition responseThe encrypted third password of band.Then, the first application program can be with the corresponding public key pair of the second private key according to the pre-stored dataThe encrypted third password is decrypted, and obtains third password, and send connection to the first container based on the third password and askIt asks, to establish connection.
By a kind of method for communication that this specification embodiment provides, first terminal applies journey by the way that container reception is multipleThe posting request that the first application program of connection is sent is established in sequence with container.Wherein, it is carried in posting request to be releasedMessage and the corresponding first message theme of message to be released.Then, first terminal applies journey according to pre-stored in containerThe subscribing relationship of sequence and message subject determines the second application program for subscribing to first message theme in multiple application programs, and leads toIt crosses container and sends message to terminal belonging to the second application program.In this way, when the first container receives first in first terminalIt, can be to all second application programs for subscribing to the first message theme after application issued to the message of first message themeAffiliated terminal forwards the message, to realize communication point-to-multipoint between first terminal and other terminals.
It based on the same technical idea, should as shown in figure 3, this specification embodiment additionally provides a kind of device of communicationDevice is deployed in first terminal and has agent functionality, which corresponds to multiple application programs in multiple terminals,Multiple terminals include first terminal, which includes:
First receiving module 310, for receiving the first application program for establishing connection in multiple application programs with the deviceThe posting request of transmission carries message to be released and the corresponding first message theme of message to be released in posting request,First application program is the application program in application program or other terminals in first terminal;
First determining module 320, for the subscribing relationship of application program according to the pre-stored data and message subject, determination is moreThe second application program of first message theme is subscribed in a application program;
First sending module 330, for sending message to terminal belonging to the second application program.
Optionally, the device further include:
Second receiving module, for receiving the subscription request that third application program is sent in multiple application programs, subscription is askedSecond message theme is carried in asking;
Adding module, for adding third application in the subscribing relationship of pre-stored application program and message subjectThe subscribing relationship of program and second message theme.
Optionally, the device further include:
Third receiving module carries encryption in connection request for receiving the connection request of the first application program transmissionFirst password afterwards, encrypted first password are to obtain after the first application program encrypts first password by the first private keyIt arrives;
Deciphering module solves encrypted first password for the corresponding public key of the first private key according to the pre-stored dataIt is close, obtain first password;
Second determining module determines the first application for the corresponding relationship of application program according to the pre-stored data and passwordCorresponding second password of program;
Second sending module sends to the first application program and connects if identical as the second password for first passwordSuccess response, so that the first application program and container establish connection;
Third sending module sends to the first application program and connects if different from the second password for first passwordFailure response.
Optionally, the device further include:
4th receiving module, for receiving the password acquisition request of the first application program transmission;
Module is obtained, for obtaining the corresponding third password of the first application program;
Encrypting module encrypts third password for the second private key according to the pre-stored data, obtains encryptedThree passwords;
4th sending module obtains response for sending password to the first application program, and password obtains to be carried in responseEncrypted third password.
Optionally, module is obtained, is specifically used for:
According to the corresponding relationship of application program and password pre-stored in container, the first application program corresponding is determinedThree passwords.
Optionally, module is obtained, is specifically used for:
According to preset password create-rule, the corresponding third password of the first application program is generated;
The device further include:
Memory module, for storing the corresponding relationship of the first application program and third password into device.
By a kind of device for communication that this specification embodiment provides, first terminal applies journey by the way that container reception is multipleThe posting request that the first application program of connection is sent is established in sequence with container.Wherein, it is carried in posting request to be releasedMessage and the corresponding first message theme of message to be released.Then, first terminal applies journey according to pre-stored in containerThe subscribing relationship of sequence and message subject determines the second application program for subscribing to first message theme in multiple application programs, and leads toIt crosses container and sends message to terminal belonging to the second application program.In this way, when the first container receives first in first terminalIt, can be to all second application programs for subscribing to the first message theme after application issued to the message of first message themeAffiliated terminal forwards the message, to realize communication point-to-multipoint between first terminal and other terminals.
Based on the same technical idea, this specification embodiment additionally provides a kind of terminal, including memory and processor,It is stored with executable code in memory, when processor executes executable code, realizes the method that above-mentioned first terminal executes.
Based on the same technical idea, this specification embodiment additionally provides a kind of computer readable storage medium, thereonIt is stored with computer program, when computer program executes in a computer, computer is enabled to execute what above-mentioned first terminal executedMethod.
Those skilled in the art are it will be appreciated that in said one or multiple examples, function described in the inventionIt can be realized with hardware, software, firmware or their any combination.It when implemented in software, can be by these functionsStorage in computer-readable medium or as on computer-readable medium one or more instructions or code transmitted.
Above-described specific embodiment has carried out further the purpose of the present invention, technical scheme and beneficial effectsIt is described in detail, it should be understood that being not intended to limit the present invention the foregoing is merely a specific embodiment of the inventionProtection scope, all any modification, equivalent substitution, improvement and etc. on the basis of technical solution of the present invention, done should allIncluding within protection scope of the present invention.