Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket.io not sending a message to all connected sockets
    primarykey
    data
    text
    <p>I'm trying out node.js and socket.io. I wan't to use to remove a ping function I have to get updates from my server. Here is an example code of what I'm doing:</p> <pre><code>var app = require('http').createServer(), io = require('socket.io').listen(app), cp = require('child_process'); app.listen(8080); //I check a global value for all the connected users from the php command line var t = setInterval(function(){ cp.exec('/usr/bin/php /Users/crear/Projects/MandaFree/symfony api:getRemainingMessages', function(err, stdout){ if (err) { io.sockets.emit('error', 'An error ocurred while running child process.'); } else { io.sockets.emit('change', stdout); } console.log('Remaining messages: ' + stdout); }); }, 3000); var remaining = io.of('/getRemainingMessages') .on('connection', function(socket){ socket.on('disconnect', function(){}); }); </code></pre> <p>The Issue here, is that when I call io.sockets.emit() the debug console tells me it is doing something, but it looks like it is not getting to the clients. Because they are doing nothing.</p> <p>I use to have one interval for every connected client, and when I used socket.emit() it did worked. But it is not the optimal solution.</p> <p><strong>UPDATE:</strong> Here is my client side code.</p> <pre><code>var remaining = io.connect('http://127.0.0.1:8080/getRemainingMessages'); remaining.on('change', function(data){ console.log('Remaining messages: ' + data ); $('#count').html(data); }); remaining.on('error', function(error){ console.log(error); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload