-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
46 lines (35 loc) · 837 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
37
38
39
40
41
42
43
44
45
46
'use strict';
const os = require('os');
const path = require('path');
const jstp = require('..');
const maxConnections = +process.argv[2];
const app = new jstp.Application('app', {
iface: {
method(connection, argument, callback) {
callback(null);
},
},
});
const server = jstp.net.createServer([app]);
server.maxConnections = maxConnections;
const socket = path.join(
process.platform === 'win32' ? '\\\\.\\pipe' : os.tmpdir(),
'jstp-ipc-test'
);
const terminate = () => {
server.close();
process.exit(0);
};
process.on('message', ([type]) => {
if (type === 'stop') {
terminate();
}
});
process.on('SIGINT', terminate);
server.listen(socket, error => {
if (error) {
console.error(error);
}
console.log(`Server listening on ${socket} 🚀`);
process.send(['started', socket]);
});