Site: http://oss.metaparadigm.com/jsonrpc
It is a piece of middleware which allows client-side JavaScript to invoke server-side Java method. It uses xmlhttprequest to send requests to server.
Example
function onLoad() { jsonrpc = new JSONRpcClient("JSON-RPC"); } function clickHello() { var whoNode = document.getElementById("who"); var result = jsonrpc.hello.sayHello(whoNode.value); alert("The server replied: " + result); }
Procedure
Every time a new JSONRpcClient object is created, the system automatically asks the server for the method list.
Then all these methods are added to this newly created instance. When the user program invokes a certain method, the system marshalls the
parameters and method names and then send a message to server. The server unmarshalls the received message and invokes the corresponding
function at server side. After the function is executed, the result is marshalled and sent to client.
At server side, the library provides a bridge which can be used by a class to expose its methods to clients.
Improvement
To improve performance, that Javascript library maintains a pool of xmlhttprequest instances. Every time a new
xmlhttprequest object is required, the pool is searched at first. If there is available xmlhttprequest instance, it is used. Or else, new xmlhttprequest instance is created.
No comments:
Post a Comment