SocketIO has become a popular day by day for it’s real time bidirectional communication. Instead of using a time interval based checking, we can use socket based communication which is more efficient in terms of using network bandwidth. It’s extremely easy to build a chat client, analytics, collaborative editing, streaming and lots of real time activities by using socketIO.
Here I’m describing how socketIO can be used to make a notification system. I’m using nodeJs here. In order to install socketIO, we can use this command:
npm insatall — save socket.io
I’m using an express app here. If you use a different framework, your mileage may vary.
In the server.js file, I added the following lines:
From that lines of code, we can see, I’m using a receiver helper module which contains the socket related methods. And on the other hand, the socketIO helper module is being used as accessor module.
Here is the code of socketio.js accessors.
Here is a sample of receivers module.
You can use any string value instead of ‘generated notification’ and the second parameter of the emit method would be the text of the notification message.
In order to get the notification value and send back response from the client side, this can be a way around.
In the html <body> tag, use the following line:
This is the simplest way to use socketIO for building notification system. You can write different logic for notification authorization, classification and customization.
Please ask me any question at @mrezaurrahman twitter handler.