Socket.IO & Realtime application

We all once believed that the development of a realtime application is difficult . But that's worng

in fact it's not that difficult especialy for web developer the Reaseon ? 


Socket.IO 

  


To simplify things Socket.io is nodejs module (server side JavaScript)  to send and receive a kind of 

events.

Basically, you send and listen to emit events on both side front and back end 


 To install it on your project
npm install socket.io
you need also to include javascript library in the front end

<script src="/socket.io/socket.io.js"></script><script>

exemple

 Client side :
socket.on   means we listen to an event called  news
socket.emit we send an event called my other event to the server




Server Side :

io.on('connection' is listen to when the user is connected  when logged or not i takes socket
as parametre socket conatins all connected users
socket.emit  send an event called news to the client
socket.on means we listen to an event 'my other event'
To sum it the when the user is connected the server emit news event  and when the user recive it,he send another event  'my  other event' and the server listen it

NB : you can also send an event to all users exept you by using emit.broadcast
ex when chat user is connected notify all user exept you


Comments

Popular posts from this blog

Twitter API with PHP

Realtime Chat Application with CakePHP and Socket.IO #1

Install Bash on Windows 10