I. Installation of Dnode
1, for Nodejs, performing
Copy Code code as follows:
2, for PHP, using composer to install Dnode PHP
Execute the following statement to download the composer
Copy Code code as follows:
$ wget Http://getcomposer.org/composer.phar
Create a file Composer.json, and then fill in the following statement,
Copy Code code as follows:
{
"Require": {
"Dnode/dnode": "0.2.0"
}
}
Perform the following statement installation,
Copy Code code as follows:
$ sudo php composer.phar install
Second, the use of Nodejs to create a simple server program, Server.js
Copy Code code as follows:
var Dnode = require (' Dnode ');
var Server = Dnode ({
Zing:function (n, CB) {CB (n * 100)}
});
Server.listen (7070);
third, the use of PHP to create a client program client.php, which need to refer to the Dnode folder just installed file autoload.php
Copy Code code as follows:
<?php
Connect to Dnode server running in Port 7070 and call
Zing with Argument 33
Require ' lib/vendor/autoload.php ';
This is the class we ' re exposing to Dnode
Class Temp
{
Compute the client ' s temperature and stuff that value into the callback
Public function temperature ($CB)
{
}
}
$loop = new React\eventloop\streamselectloop ();
$dnode = new Dnode\dnode ($loop, New Temp ());
$dnode->connect (7070, function ($remote, $connection) {
Remote is a proxy object so provides us all methods
From the server
$remote->zing (function ($n) use ($connection) {
echo "n = {$n}\n";
Once we have the result we can close the connection
$connection->end ();
});
});
$loop->run ();
?>
Four, the implementation of server-side
Copy Code code as follows:
v. Execute client-side Invoke server program
Copy Code code as follows:
This invokes the server-side addition program, and then outputs the result
Copy Code code as follows: