-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
28 lines (22 loc) · 765 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
const decodeClass = require('./decode')
const net = require('net')
const redis = require('redis')
const conf = require('./conf.json')
const server = net.createServer(function(socket) {
console.log('client connected')
const decode = new decodeClass(redis.createClient(), socket)
socket.on('end', function() {
console.log('client disconnected')
//Si cliente se deconecta
decode.redisClient.quit()
})
socket.on('data', function(data){
socket.write( data.byteLength === 17 ? decode.imei(data) : decode.rawData(data) )
decode.pendingCommand()
});
socket.on('drain', data =>{
console.log('Vacio', data)
})
});
server.listen(conf.port);
console.log('Listening on port:', conf.port)