I have created a web server architecture in nodejs which serves web pages when running. On the other hand I have a Qt GUI application. I need to make an interface between these two. I have already created the connection between these two using QProcess (the server now starts from this Qt application) Now I want to exchange some data between them, for example a random message on the web page from GUI and back. Is stdin/out of any use here? Can you please guide me through this? Here is my server code:
`function init() {
var __website = path.join(__dirname, 'Website/');
var __css = path.join(__dirname, 'css/');
app.use(bodyParser.json());
app.use(express.static(path.join(__website)));
app.get('/', function (req, res, next) {
res.render('index', function (err, html) {
res.send(html);
});
});
app.get('/data/:iValue', function( req, res) {
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk != null) {
res.json({response: chunk.toString("UTF-8")});
}
});
process.stdout.write('request_data:' + temperature);
});
}
function initSocket() {
var Session = require('express-session');
var MemoryStore = require('session-memory-store')(Session);
var session = new Session({
store: new MemoryStore(),
secret: 'supersecret',
resave: true,
saveUninitialized: true
})
//io = require('socket.io')(https);
io = new ioServer();
io.use(ios(session));
// In-memory storage
// Begin listening for a websockets connection
io.on('connection', function (socket) {
socket.emit('setRange', data.min, data.max);
socket.emit('setEmails', data.emails);
setInterval(function () {
var temperature;
//var temperature = Math.floor((Math.random() * 20) + 15);
socket.emit('updateTemperature', {
temperature: temperature
});
if (temperature < data.min || temperature > data.max) {
// console.log('alert! ' + temperature + ' min:' + data.min + '
max:' + data.max)
sendEmail(temperature);
socket.emit('alert', {
temperature: temperature,
message: 'Temp is outside of Value Range'
});
}
}, 2000);`
Yes, QProcess
can grip stdout
, stderr
. you can listen to its output with readyReadStandardOutput signal emitted by the process then read by any of qprocess read methods like readAllStandardOutput().. also you can have your gui send messages to nodejs standard input with QIODevice::write(const char *data)
inherited function.