-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
34 lines (28 loc) · 980 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
32
33
34
var thrift = require("thrift");
var Messager = require("./gen-nodejs/Messager.js");
var ttypes = require("./gen-nodejs/example_types.js");
var transport = thrift.TBufferedTransport;
var protocol = thrift.TBinaryProtocol;
var connection = thrift.createConnection(0, '/tmp/messager.em', {transport: transport, protocol: protocol});
connection.on('error', function(err){
console.log("Got error: " + err);
});
var client = thrift.createClient(Messager, connection);
var myid = 0;
var maxid = 100;
var interval = setInterval( function() {
var msg = new ttypes.Message({id: myid++, name: "toto", desc: "hello world!"});
client.send(msg, function(err){
if(err){
console.log("send got errors for id " + msg + ", booohoo: " + err);
}
});
if (myid > maxid) {
process.exit(0);
}
}, 1);
process.on('exit', function(code) {
clearInterval(interval);
connection.end();
console.log("sent " + myid + " messages");
});