我需要使用哪些技术才能从node.js服务器向Android客户端发送通知?例如,用户A将用户B添加为好友,在此时,用户B应收到一条通知,告知其用户A希望将其添加为好友。我对node.js不熟悉,请问您应该使用什么技术来实现发送此类通知。
https://en.wikipedia.org/wiki/MQTT
https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
Node.js非常支持这两个方面。Android有一个MQTT客户端,这里有一个示例:http://androidkt.com/android-mqtt/。client.on('message', function (topic, message) {
// Messages are Buffer objects.
console.log(message.toString())
client.end()
})
app.post("/addFriend", function(req, res, next){
console.log("Friend request added");
// Write to db.
// Send a message
mqttClient.publish('friends-topic', JSON.stringify({event: 'newfriend', id: '10122', name: 'Mark' }))
res.end('ok', 200);
});
node-gcm
模块。