2012年3月21日星期三

Dr Dre HeadphonesDnodeDnode is an asynchronous bidirectional remote method invocation of the lib

DnodeDnode is an asynchronous bidirectional remote method invocation of the library .Network socket and websocket wind & # 26684 ;socket.io communication has become possible ,so the system processes can communicate with each other and can be run in the browser end user process using the same interface .
Remote method invocation ( RMI ) is an object-oriented remote procedure call cousins .In RMI, connecting each end holding the other end can call the method of a remote object .All Dnode remote method calls are asynchronous .
Unlike a clear return results to practice ,the host ( distal) method by performing a callback method to transfer back & # 20540 ;to another end connection (local ) ,and the callback is passed as an argument .
These callbacks in those who define their end (usually the client ) to be executed ,and their one agent is delivered to the remote ,so there is no Eval ( ) here is a simple example :/ / Server: VAR DNode = require ( ) ;VAR server = DNode ( {timesTen :function ( n ,f ) {f ( n * 10 ) } ,} ) .
Listen ( 6060) ;/ / client: VAR DNode = require ( ) ;VAR sys = require ( ) ;DNode.connect ( 6060 ,Coach Bag,function ( remote ) {remote.timesTen ( 5 ,function ( result ) { sys.
puts ( result ) ;/ / 5 * 10 = = 50 } ) ;} ) ;then ,Moncler Sale,the opening of the two Cygwin client ,respectively, compile and execute the Server end Client code and end code: Server: Client: unlike many asynchronous RPC systems ,Dnode allows programmers to function as a parameter passed to the remote method .
Callback will be automatically refresh and from the parameter list recursive is collected .So they can be arbitrarily nested .In addition ,connecting each side can call the other side and the other side is provided for the callback method ,the callback method for its own could be any can be serialized as an JSON parameter method .
Two examples about the client calls a method and server ,server and client calling a method example :/ / Server: VAR DNode = require ( ) ;DNode ( function ( client ) {this.
timesX = function ( n ,f ) {client.x ( function ( x ) { f ( n * x ) ;} ) ;} } ) . Listen ( 6060) ;/ / client: VAR DNode = require ( ) ;VAR sys = require ( ) ;DNode ( {X: function ( f ) {f ( 20) } } ) .
Connect ( 6060 ,function ( remote ) {remote.timesX ( 3 ,function ( RES ) {sys.puts ( RES ) ;} } ) ;} ) ;implementation method ibid ,effects are as follows :the DNode browser sample in the browser and node.
js Dnode server between the websocket type connecting the feasibility to thank .The following example should run on Chrome ,Firefox ,Opera and IE 5.5& # version of the above 43 .This example from node_modules dnode examples web-http :server.
js var HTTP = require ( ) ;VAR FS = require ( ) ;VAR dnode = require ( ) ;VAR index = fs.readFileSync ( dirname + _ _ ) ;VAR server = http.createServer ( function ( req ,RES ) {if ( req.
url = = = = = = = = = = = = = = = = = = ) {res.writeHead ( 200 ,{ : / HTML ) ;res.end ( index ) ;} } ) ;dnode ( function ( client ) {this.cat = function ( CB ) {CB ( ) ;} ;} ) .
Listen ( server ) ;server.listen ( 6857) ;console.log ( http: / / localhost: 6857 / ) ;note: _ _ dirname indicates the files in the folder ,fs.readFileSync method for synchronous read file ,return & # 20540 ;is a binary stream .
Index.html < ;html> ;< ;head> ;< ;script SRC = " ;type = " ;dnode.js" text / javascript" ;> ;< ;< ;script / script> ;type = " ;text / javascript" ;> ;window.
onload = function ( ) {DNode.connect ( function ( remote ) {remote.cat ( function ( says ) {document.getElementById ( ) . InnerHTML = says ;} ) ;} ) ;} ;< ;script> ;< ;< ;body> ;head> The cat says < ;span id = " ;says" ;> ;< ;?/ span> ;.
< ;/ body> ;< ;/ html> ;compile :Note: must navigate to the file directory to use node command followed by a relative path under the name of the file to compile the JS .In the browser address bar enter :http: / / localhost: 6857 / ,can get the following output :analytic :because the HTTP server is listening from the 6857 port ,and when there is a request ,and find that followed the / ,then the output index.
html to the client .Because the server DNode listening on port 6857, while the client page finishes loading ,began to connect the server DNode ,and to implement the callback .From the server agent ( remote ) ,defined in the server implementation method cat ( ) ,cat method need a function ( client definition ) as a parameter .
The final ID says span label text into meow .Install Dnode can be obtained by NPM ,UGG UK,NPM is a node.js library package manager .You can pass the following command installation ( in cygwin,Dr Dre Headphones, execute the following command ) : NPM install dnode Dnode relies on the following Module: Socket.
IO-node ,bufferlist ,traverse .All of these can be obtained by NPM ,and when you are performing the above order,Moncler Outlet, they are automatically installed .Of course there are some interesting examples
Related articles:

没有评论:

发表评论