nodejs.thrift
struct User {
1: i64 uid,
2: string username
}
service Nodejs {
User index(1: User user)
}
client.js
var thrift = require(‘thrift’);
var Nodejs = require(’./gen-nodejs/Nodejs.js’);
var ttypes = require(’./gen-nodejs/nodejs_types.js’);
var connection = thrift.createConnection(‘127.0.0.1’, 15300);
connection.on(“error”,function(e){
console.log(e);
});
var client = thrift.createClient(Nodejs, connection);
var user = new ttypes.User({
uid: 123,
username: “wangxiuwen”,
info: ‘jiaban’
});
client.index(user, function(err, res){
console.log(res, typeof res);
});
server.js
var thrift = require(‘thrift’);
var Nodejs = require(’./gen-nodejs/Nodejs.js’);
var ttypes = require(’./gen-nodejs/nodejs_types.js’);
var tf_methods = require(’…/models/tf_methods.js’);
var server = thrift.createServer(Nodejs, tf_methods);
server.listen(15300);
server.on(‘error’,function(e){
console.log(‘e’,e);
});
module.exports = tf_methods;