-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
63 lines (57 loc) · 1.48 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var exports = module.exports = {};
var tftp = require('tftp');
var tftpServer = null;
var fs = require('fs');
var streamServer;
var mcServer;
exports.startTFTP = function(opts,cb) {
var tftp = require('tftp');
console.log('port: ' + opts.port)
api.node.tftpServer = tftp.createServer ({
address: opts.host || '127.0.0.1',
port: opts.port || 69,
root: opts.root || '../../tftp/',
denyPUT: true,
});
api.node.tftpServer.listen();
cb();
}
exports.readConfig = function() {
myConfig = JSON.parse(fs.readFileSync(__dirname + '/config.json'));
return myConfig;
}
exports.stopTFTP = function(cb) {
tftpServer.on('close', function() {
closed = true;
if (!connections.length) {
return console.log ('TFTP Server closing...');
}
// Abort all the current transfers
for (var i = 0; i < connections.length; i++) {
connections[i].abort ();
}
});
tftpServer.close ();
cb();
}
exports.startStreamingServer = function(opts) {
streamFile = __dirname + '/streamer.js';
fork = require('child_process').fork;
streamServer = fork(streamFile,[opts.host,opts.key,opts.role],{
stdio: 'pipe',
});
}
exports.stopStreamer = function(cb) {
streamServer.kill('SIGINT');
cb();
}
exports.stopMCServer = function(cb) {
mcServer.kill('SIGINT');
}
exports.startMCServer = function(opts) {
mcFile = __dirname + '/multicast.js';
fork = require('child_process').fork;
mcServer = fork(mcFile,[opts.host,opts.taskID],{
stdio: 'pipe',
});
}