Thanks to the success of my previous post about a Node.js push notification server, now in this post I would go further realizing a server that is able to read from a MySql database and then stream those data via websocket to many client connected on the same page. The idea behind this shit is that we will broadcast our data without having any timer on the client but only a ( kind of )timer on the server.
First of all we must install the modules needed for this example.

This node js module is needed to read a MySQL database

$ npm install mysql@2.0.0-alpha9

And then Socket.io to deal with the HTML5 websocket

$ npm install socket.io

Once we have all the nodejs modules installed we could set the Javascript code to run on the server.
The first part of our code is needed to set up the connection with database and to load the html ( client.hmtl ) page in which we are going to print the data fetched with our MySql queries.

 

http://www.gianlucaguarini.com/blog/push-notification-server-streaming-on-a-mysql-database/

Advertisements