var thrift = require(‘thrift‘);
var UserService = require(‘./gen-nodejs/UserService.js‘),
ttypes = require(‘./gen-nodejs/user_types‘);
var users = {};
var server = thrift.createServer(UserService, {
add: function(user, callback) {
console.log("server stored:", user.uname);
users[user.uid] = user;
callback();
}
});
server.listen(7911);
console.log(‘server start‘);
var thrift = require(‘thrift‘);
var UserStorage = require(‘./gen-nodejs/UserStorage.js‘),
ttypes = require(‘./gen-nodejs/user_types‘);
var connection = thrift.createConnection(‘localhost‘, 9090),
client = thrift.createClient(UserStorage, connection);
var user = new ttypes.UserProfile({uid: 1,
name: "Mark Slee",
blurb: "I‘ll find something to put here."});
connection.on(‘error‘, function(err) {
console.error(err);
});
client.store(user, function(err, response) {
if (err) {
console.error(err);
} else {
console.log("client stored:", user.uid);
client.retrieve(user.uid, function(err, responseUser) {
if (err) {
console.error(err);
} else {
console.log("client retrieved:", responseUser.uid);
connection.end();
}
});
}
});