-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.js
22 lines (21 loc) · 830 Bytes
/
device.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var net = require('net');
var StringDecoder = require('string_decoder').StringDecoder;
var decoder = new StringDecoder('utf8');
var request = require('request');
var port = 3001;
net.createServer(function (socket) {
console.log('Socket connected from: ' + socket.remoteAddress + ":" + socket.remotePort);
socket.on('data', function (data) {
var message = decoder.write(data);
console.log('Client: ' + message);
socket.write('OK');
request('commandvtsurlhere/post?data=' + message, function (err, response, body) {
console.log("Sent data to HEROKU");
});
});
socket.on('end', function () {
console.log("Connection closed");
console.log("----------------------------------------")
});
}).listen(port);
console.log('Listenting on port '+port);