二、利用nodejs创建简单server程序, server.js 复制代码 代码如下: var dnode = require("dnode"); var server = dnode({ zing: function (n, cb) { cb(n * 100) } }); server.listen(7070);
三、利用php创建客户端程序client.php, 其中需要引用刚才安装的dnode文件夹里面的文件autoload.php 复制代码 代码如下: <?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 ReactEventLoopStreamSelectLoop(); $dnode = new DNodeDNode($loop, new Temp()); $dnode->connect(7070, function($remote, $connection) { // Remote is a proxy object that provides us all methods // from the server $remote->zing(33, function($n) use ($connection) { echo "n = {$n}
"; // Once we have the result we can close the connection $connection->end(); }); }); $loop->run(); ?>