-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
SOURCE: https://gist.github.com/tedmiston/5935757 | ||
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp | ||
server, but for some reason omit a client connecting to it. | ||
And connect with a tcp client from the command line using netcat, the *nix | ||
utility for reading and writing across tcp/udp network connections. I've only | ||
used it for debugging myself. | ||
$ netcat 127.0.0.1 1337 | ||
MODIFIED FOR SAVING INPUT DATA TO A FILE | ||
*/ | ||
|
||
var _ = require('c-struct'); | ||
|
||
var soh_t = { | ||
length : 0, | ||
id : 1, | ||
delay: 1000 | ||
}; | ||
|
||
var _soh_t = new _.Schema({ | ||
length : _.type.uint8, | ||
id : _.type.uint8, | ||
delay : _.type.uint8 | ||
}); | ||
|
||
_.register('soh_t', _soh_t); | ||
|
||
//Log | ||
var log = require('./utils/logger.js').Logger; | ||
|
||
//Config | ||
var config = require('./config.json'); | ||
|
||
var net = require('net'); | ||
|
||
var server = net.createServer(function(socket) { | ||
socket.on('data', function (input) { | ||
log("Received data: " + input.toString('utf8'), "info"); | ||
|
||
soh_t.delay = input; | ||
}); | ||
|
||
setInterval(function () { | ||
soh_t.length = Object.keys(soh_t).length; | ||
|
||
var buff = _.packSync('soh_t', { | ||
length : soh_t.length, | ||
id : soh_t.id, | ||
delay : soh_t.delay | ||
}); | ||
|
||
console.log(buff); | ||
|
||
socket.write(buff); | ||
}, 1000); | ||
}); | ||
|
||
server.listen(config.web_port, config.web_host); | ||
console.log("Listening on port " + config.web_port + " on " + config.web_host); | ||
|
||
|