lpdg-iomanager v1.0.4
lpdg-iomanager
An IOManager that saves the generated result to files, is able to use websockets to stream or let a client poll for data or just returns the value of the lpdgenerator.
Usage
First install lpdg-iomanager:
npm install lpdg-iomanager -s
const lpdgenerator = require('lpdgenerator');
const lpdgiomanager = require('lpdg-iomanager')
var generator = new lpdgenerator();
var manager = new lpdgiomanager();
manager.run(generator);
And then run the program with an input file as parameter:
node myprog <input-file>
Input
There is an example input file in the root.
Name | Description | Default |
---|---|---|
time:interval | The interval at which the parkings get updated and the stream sends updates | 30 |
file:output | The output directory | "" |
file:output_meta_data | Bool to see if meta data should be put in the file | false |
file:extension | Defines the extension of the generated files | "" |
file:name_format | Defines the format of the output filenames. DEFAULT : city-YYYY-MM-DDThhmmss , UNIX : UNIX timestamp of beginning of interval. | "DEFAULT" |
file:split | If files of cities should be split, if false will ignore "time:time_per_file" | true |
io:mode | Mode can be FILE, STREAM, POLL or STRING. If something other then FILE is used, most "file:xxxxx" variables will be ignored | "FILE" |
io:port | Port at which the websockt is made | 8080 |
Websockets
When the "io:mode" is STREAM or POLL, the manager will create a websocket to send data over the network.
STREAM
When streaming, the IOManager will send data to subscribed clients every "time:interval" seconds. To subscribe, clients have to send a JSON object with following parameters:
Name | Description |
---|---|
type | Can have te value INFO (if we just want to get info on the cities and parkings), SUB (if we want to subscribe to a city) or UNSUB (if we want to unsubscribe from a city) |
city | If the type of the request is SUB or UNSUB this value should be the number of the city we want to (un)subscribe |
Sample client
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080');
ws.on('open', function open() {
ws.send('{"type" : "SUB", "city":0}');
});
ws.on('message', function incoming(data) {
console.log(data.toString());
});
POLL
When the mode is POLL, clients have to requist data every time they want to have an update. CLients should send a JSON object with following parameters:
Name | Description |
---|---|
type | Can have te value INFO (if we just want to get info on the cities and parkings), GET (if we want to get the parking data) |
city | If the type of the request is GET this value should be the number of the city we want |
time | If the type of the request is GET this value should be the begin value of the data |
Sample client
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080');
ws.on('open', function open() {
ws.send('{"type" : "GET", "city":0, "time": "1970-01-01T00:00:00"}');
});
ws.on('message', function incoming(data) {
console.log(data.toString());
});
FILE
File output will just output the result for every city in separate files.