A kind of cross-platform remote procedure calling (PRC) method
Technical field
The present invention relates to communication technical field, particularly relate to a kind of cross-platform remote procedure calling (PRC) method.
Background technology
In network technology, platform refers to that software systems pass through to disclose its application programming interface (API) or function is not needing to make external program increase the function of software systems or use the application of software systems resource under the condition changing source code.In this way, website can not only provide easy access to web webpage to user, can also carry out complicated data interaction, thus web site is converted to the development platform with operating system equivalence.This field current flourish, the development trend in open platform is also described to a certain extent the Internet future just, the phenomenon that mobile-terminal platform presents especially " letting a hundred schools contend ".
But, incompatible between the mobile-terminal platform of current main-stream.For different mobile-terminal platforms, do not have yet can be unified application programming interface and language.Industry is recognized, this incompatibility will become the major obstacle of mobile-terminal platform development.From external program, the angle of especially mobile terminal application and development, in order to adapt to different mobile-terminal platforms, has to use different programming languages and API repeated encoding on multiple platforms.From the angle of code maintenance, need to safeguard many parts of codes for same project simultaneously, once programmed logic changes, then need a large amount of code revisions and regression test.In addition, economically, develop simultaneously and safeguard the application program of multiple platform, by manpower huge for cost enterprise and time cost.
Therefore, there is coordination process complexity in the communication between current mobile-terminal platform, repetition rate is high, the defect that later maintenance is difficult and cost is high.
Summary of the invention
The invention provides a kind of method of cross-platform remote procedure call, be intended to overcome and between mobile-terminal platform, communicate that the coordination process that exists is complicated, repetition rate is high and the defect of later maintenance difficulty.
The invention provides a kind of method of cross-platform remote procedure call, comprise the following steps:
S1, Application and Development in the uniform client assembly of multiple Mobile data platform, and divides presentation layer, Business Logic and the data interaction layer in described client component;
S2, user end to server sends the request of calling remote process and obtaining return value, and uses HTTP as the carrier of host-host protocol to the request message after described server transmission encapsulation;
S3, once the Servlet of described server receives the described request message that described client sends, namely described server starts to resolve described request message;
S4, the access rights of client described in described server authentication; Described client is by after checking, and the target function name in described request message is mapped to specified function by described server, performs described specified function and returns results message to described client.
Further, described request message comprises ID and the machine code information of target function name, parameter list and the described client that needs call.
Further, after described server brings into operation, from preset configuration, read whole addressable function list, and described function list is loaded into runtime internal memory, to ensure that described function list calls by reflex mechanism.
Further, after described client obtains the access rights of described server imparting, described server extracts the target function information of described target function name correspondence, by the described specified function of reflection access in internal memory, and obtains execution result.
Further, described in described server authentication, the method for the access rights of client comprises the following steps:
After described server parses described request message, ID and the machine code of extracting described client in the specific fields of analytically content compare in a database; Give the described client access authority by checking.
Further, described result message uses HTTP to be sent to described client as the carrier of host-host protocol.
Read for the ease of programmer and write, and be easy to machine parsing and generate, described request message and result message all adopt JSON coded format.
Further, described server adopts the WEB middleware supporting J2EE standard.
For farthest avoiding the Consumer's Experience applied with during multiple Mobile data platform to lose, described presentation layer has two kinds or more different user interface components to be applied to multiple Mobile data platform.
For improving the level of resources utilization of system, the service logic layer operation in described client component and data interaction layer operation realize by described server.
Compared with prior art, cross-platform remote procedure calling (PRC) method disclosed in this invention has that occupying system resources is few, transmission is stable, cost is low and the advantage that applicability is wide.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, accompanying drawing in the following describes is some embodiments of the present invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to these accompanying drawings.
Fig. 1 is the flow chart of a kind of embodiment of the cross-platform remote procedure calling (PRC) method of the present invention.
Embodiment
For making the object of the embodiment of the present invention, technical scheme and advantage clearly, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
Shown in Figure 1, current main flow mobile-terminal platform comprises Android device, other mobile device etc. of wince equipment, ios device and desktop system.The API provided due to each system is different with system bottom framework, so incompatible between each mobile-terminal platform, the program on an equipment is also difficult to call the resource on another equipment.In fact, we often need on multiple mobile device, set up a system, and by this system, the program that realizes carries out information exchange across mobile platform.This example is too numerous to enumerate.Such as, if will develop a set of mobile phone A PP, the minimum release of general needs two versions, namely for the APP of Android and IOS two cover system, and the APP of current pure unit is considerably less.Generally the Internet support is all needed to provide real time data processing; In addition some sensitive informations are difficult to be placed on client executing with the part be awkward, so at least need a server go deal with data as data processing centre and realize service logic.Again such as, the task of the client executing of mobile device oneself, but need to provide backend file service etc. by server.When much similar, remote procedure call is all needed to provide a kind of cross-platform communication mechanism.
The frame structure of the client and server of multiple mobile platform is regarded as a kind of system of relative separation by the cross-platform remote procedure calling (PRC) method disclosed in the present embodiment, the operation of the part of data access is performed by server, and by the mutual front-end operations of client completing user, adopt in such a way, farthest can improve the utilance of system resource, also a large amount of numerical value process operation can be placed in the strong system of data-handling capacity and run, thus alleviate the burden of front end mobile platform terminal.
Cross-platform remote procedure calling (PRC) method disclosed in the present embodiment comprises the following steps:
S1, Application and Development in the uniform client assembly of multiple Mobile data platform, and divides presentation layer, Business Logic and the data interaction layer in described client component.Service logic layer operation in client component and data interaction layer operation are placed and realizes on the server; And the user's interface unit in presentation layer is separated and carries out otherness exploitation.Described presentation layer has two kinds or more different user interface components to be applied to multiple Mobile data platform.In fact, no matter on Android, IOS or windows platform, have respective a set of interaction habits, wherein visual style, changing interface, operating habit etc. are all different.Farthest can avoid the loss of Consumer's Experience according to the differentiation exploitation of Mobile data platform character, while the efficient principle of guarantee, development cost can be maintained in rational scope.
S2, client terminal start-up program, connects with described service end.Server brings into operation, and server reads whole addressable function list from preset configuration, and described function list is loaded into runtime internal memory, to ensure that described function list calls by reflex mechanism.After having connected, described client sends the request of calling remote process and obtaining return value to described server.This request of data is packaged into message and uses HTTP(HTML (Hypertext Markup Language) by client) transmit the request message after encapsulation as the carrier of host-host protocol to described server.
Specifically, in the request message after encapsulation, at least comprise the target function name that needs call, the ID of parameter list and client and machine code information.Because each development platform is substantially all built-in with comprehensive class libraries and instrument, so use HTTP as the carrier of host-host protocol, even under the development environment using various language at multiple Mobile data platform and framework, also stable transfer of data can be ensured.
Message is preferably JSON coded format.JSON is a kind of data interchange format of magnitude, adopts the text formatting being totally independent of language, but has continued to use the custom of the main flow programming languages such as similar C3, JAVA equally.Certainly, as an alternative, the coded format serializing message of other form can also be adopted, as XML etc.But the feature of JSON itself determines and adopts the message of JSON coded format to have good legibility, is convenient to programmer and reads and write, and is easy to machine parsing and generates simultaneously.Compared with XML, the form of JSON is more succinctly short and small, and the size of data after generation changes little, and is easy to process.Particularly in the face of remote procedure call needs the application demand processing large amount of complex data like this, the advantage of JSON just seems very outstanding.
S3, once the HTTP that the Servlet of server end receives the transmission of described client asks, then responds corresponding method such as (doget or dopost) and resolves to request message get parms list and the target function name needing to call.In complete system, remote procedure call is quite frequent.So, server is after resolving message, can compare resolving from request message the client id extracted in the specific fields of content with preset configuration in a database with machine code information, and give the described client access authority by verifying, to ensure stablizing of whole system.Wherein, server adopts the standard middleware supporting J2EE.
S4, if client is by checking, namely described server gives this client access authority.Server extracts the target function information of target function name correspondence, and by the described specified function of reflection access in internal memory.After specified function has been run, server judges whether client requires to return execution result, if client requirements returns execution result, the function result being about to obtain becomes result message with client id information Reseal, client is back to as HTTP result using the JSON message format of correspondence, if client does not require to return execution result, JSON result message is become to be back to client by state information with client id information Reseal.Namely client realizes operation result by different user interface module after receiving result message.Send due to http protocol and just disconnect after receiving data, so, can complete with the transmission disconnecting judgement one secondary data.
The cross-platform remote procedure calling (PRC) method that the present embodiment provides, can realize calling of program between multiple Mobile data platform easily, overcome the defect that must use different language and API overprogram in prior art between multiple Mobile data platform.The cross-platform procedure calling (PRC) method configuration that the present embodiment provides is simple, cost is low and applicability is wide.
Last it is noted that above embodiment is only in order to illustrate technical scheme of the present invention, be not intended to limit; Although with reference to previous embodiment to invention has been detailed description, those of ordinary skill in the art is to be understood that: it still can be modified to the technical scheme described in foregoing embodiments, or carries out equivalent replacement to wherein portion of techniques feature; And these amendments or replacement, do not make the essence of appropriate technical solution depart from the spirit and scope of various embodiments of the present invention technical scheme.