-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (32 loc) · 856 Bytes
/
server.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
35
36
var fs = require("fs");
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 socket_name = "/tmp/messager.em";
var msg = 0;
function clean_socket(socket_name) {
try {
fs.unlinkSync(socket_name);
}catch(e){
console.log("...");
}
}
var server = thrift.createServer(Messager, {
send: function(message) {
//console.log(msg++ + ": " + message.id);
}
}, {transport: transport, protocol: protocol}
);
server.on("error", function(err){
if(err.errno === "ECONNRESET"){
return;
}
console.log(err);
});
clean_socket(socket_name);
server.listen(socket_name);
process.on("exit", function(code){
clean_socket(socket_name);
});