forked from skymancn/thrift-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
32 lines (26 loc) · 870 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 李",
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);
connection.end();
}
});
}
});