I have a simple nodejs server:
"use strict";
var http = require("http");
var server = http.createServer(processRequest).listen(3001, "192.168.1.4");
function processRequest(request, response) {
response.writeHead(200, {
"Content-Type": "text/html"
});
response.write("Simple HTML Page");
response.end();
}
// Buradan sonrası yeni
var io = require("socket.io").listen(server);
io.sockets.on('connection', function (socket) {
sendMessage(socket);
console.log("User Connected");
socket.on("disconnect", function () {
console.log("User Disconnected");
});
});
function sendMessage(socket) {
setTimeout(function () {
socket.emit("test");
sendMessage(socket);
}, 5000);
}
I want to get data from mysql server (remote) with nodejs and broadcasting to android phones. When the new data add in db, phones show the new data. How can i communicate with Android Client?
You need to use GCM
.
The flow will be like this:
JSON Package
node Server --------------> GCM Server ---> Android Device
|
(OS notifies app) |
V
App Connects to node and fetches the data