- What is Real-Time communication?
- Why is Real-Time communication great, and why is HTTP, the protocol driving the web not the best solution?
- How to enable Real-Time communication for WordPress using Socket.IO
date 2. Data is updated with minimum latency (as quickly as possible) setInterval(function() { $.getJSON(url, function(data) { // Updating simple text element, got: { count: x } $(dataElementSelector).text(data.count); }); }, 5000);
date 2. Data is updated with minimum latency (as quickly as possible) — at least sort of setInterval(function() { $.getJSON(url, function(data) { // Updating simple text element, got: { count: x } $(dataElementSelector).text(data.count); }); }, 10);
you var io = require('socket.io')(80); io.on('connection', function(socket) { // Event based socket.emit('event', { will: 'be received only by the socket' }); io.emit('event', { will: 'be received by everyone' }); io.volatile.emit('volatile event', { will: 'only be received if socket not busy' }); // Rooms socket.join('all the cool sockets'); socket.to('all the cool sockets').emit('hello cool sockets'); // Receiving events socket.on('private message', function(from, msg) { console.log('I received a private message by ', from, ' saying ', msg); }); socket.on('reconnect', function() { console.log('socket reconnected'); }); socket.on('disconnect', function (){ io.emit('user disconnected'); }); });
to events on the client side socket.on('news', function(data) { console.log(data); // Emitting events on the client side socket.emit('my other event', { my: 'data' }); }); </script>