yags-rpc
v0.1.0
Published
An implementation of RPC for yags server
Downloads
2
Readme
##Global yags-rpc is an implementation of RPC for YAGS
yags-rpc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
yags-rpc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with yags-rpc. If not, see <http://www.gnu.org/licenses/>.
Author : BUATHIER Quentin (Quentin01)
##Usage ###Server
var server = new (require("yags-rpc").Server)(4242);
server.on('newConnection', function(host) {
console.log('New client : ' + host)
});
server.addPath('example.log', function() {
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
console.log.apply(this, args);
return args.join(' ');
});
server.listen(function(port, host) {
if(host !== '') {
console.log('Listen on ' + host + ':' + port);
} else {
console.log('Listen on port ' + port);
}
});
###Client
var client = new (require("yags-rpc").Client)(4242);
client.on('error', function(error) {
console.log(error.toString());
});
client.addProxy('example.log');
client.connect(function(port, host) {
console.log('Connected ' + host + ':' + port);
client.example.log('Client message', 'with a lots of', 'args', function(err, resp) {
if(err == undefined) console.log('Server displays : "' + resp + '"');
else console.log(err);
client.stop();
});
});
###Display This example will show server side :
Listen on port 4242
New client : 127.0.0.1
Client message with a lots of args
And client side :
Connected 127.0.0.1:4242
Server displays : "Client message with a lots of args"