Upload
mohammed-shurrab
View
4.883
Download
5
Tags:
Embed Size (px)
DESCRIPTION
How to implement a push notification based system using: PHP/MySQL, Elephant.io, Node.js, and MQTT.
Citation preview
PHPPush Notification
SystemMohammed S Shurrab
CTO, Datrios.comCTO, UnitOne.ps
Pull vs Push!
Pull Push
Web Socket & Socket.IO
Node.js
MQQT Server & Client
PHP & Elephant.io
Ajax
PHP
Architecture
Requirements
Back-end Mosquitto server (http://mosquitto.org/)
Node.js (http://nodejs.org/)
Socket.io module (npm install socket.io)
Zeparser module (npm install zeparser)
MQTTClient (https://github.com/yilun/node_mqtt_client)
Front-end Sockit.IO (http://cdnjs.com/libraries/socket.io/)
jQuery (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js)
Client code
1. Connect to the node.js server through soket.io (L:5)2. Subscribe to some topic(s) (L:10)3. Listen to any notification for these topics (L:7-9)
Node.js code (1/3)
1. include the required modules (L:1-5)2. Specify the web socket port (L:5)3. Connect to the MQTT server (L:6)
Node.js code (2/3)
1. Listening to a successful socket connection (L:8)1. Listening to a subscribing request from the client (L:9-13)
1. Filtering the web socket data based on the topics (L:11)2. Listening to a notify request from the server (L:15-18)
Node.js code (3/3)
1. Listening to a new notification from the MQQT server (L:21)1. Sent these notification through the web socket (L:23-25)
2. Listening to a successful connection with the MQTT server and sent a test notification every 5 seconds (L:29-33)
DEMO