-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 941 Bytes
/
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
import dgram from 'dgram';
import {Buffer} from 'buffer';
import {tokenize} from "./src/protocol/cylex";
import {process} from "./src/protocol/cyrano";
const DEFAULT_UDP_PORT = 50100;
// ROUGH TESTING -- UDP testing
const server = dgram.createSocket('udp4');
server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
});
server.on('message', (msg, rinfo) => {
console.log(`server got: |${msg}| from ${rinfo.address}:${rinfo.port}`);
console.log(`tokens: ${tokenize(msg)}`);
console.log(`processing: ${process(msg)["command"]}`)
});
server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);
});
server.bind(DEFAULT_UDP_PORT);
const message = Buffer.from('|EFP2|HELLO|');
const client = dgram.createSocket('udp4');
client.send(message, DEFAULT_UDP_PORT, 'localhost', (err) => {
client.close();
});