forked from evs-broadcast/node-emberplus
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsample.js
executable file
·44 lines (41 loc) · 1.24 KB
/
sample.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
const Decoder = require('.').Decoder;
const DeviceTree = require(".").DeviceTree;
const fs = require("fs");
const LOCALHOST = "0.0.0.0";
const PORT = 3336;
fs.readFile("./embrionix.ember", (e, data) => {
let root = Decoder(data);
const TreeServer = require("./").TreeServer;
const server = new TreeServer(LOCALHOST, PORT, root);
server.on("clientError", (e) => {
console.log(e);
});
server.listen()
.then(() => {
console.log("listening");
})
.then(() => {
let tree = new DeviceTree(LOCALHOST, PORT);
return Promise.resolve()
.then(() => tree.connect())
.then(() => {
return tree.getDirectory();
})
.then(() => tree.disconnect())
.then(() => tree.connect())
.then(() => {
return tree.getDirectory();
})
.catch((e) => {
console.log(e.stack);
})
.then(() => tree.disconnect())
})
.catch((e) => {
console.log(e.stack);
})
.then(() => {
console.log("close");
server.close();
});
});