Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to have an event fire whenever the data you're interested in updating has changed, and then you need to have the client listen for that event and respond as desired.</p> <p>You don't really give a context other than "send json data to the client whenever it is updated", so assuming that you are in whatever process is updating your JSON on the server:</p> <pre><code>if (req.url === '/endpoint') { yourJSON.foo = 'bar'; // doing whatever you're interested in to the JSON socket.emit('JSON changed', yourJSON); //an event is defined by the first argument, //a value is passed with it as the second } </code></pre> <p><em>NB: Getting more fancy/thoughtful with this means changing your JSON in such a manner that the socket only emits in response to the data change (event, callback, etc). Explicating this pattern is perhaps outside the scope of the question.</em></p> <p>Then on the client, you want to define a function to handle those changes:</p> <pre><code>socket.on('JSON changed', updateFunction); //where updateFunction is a function you define //that is expecting arguments that match the output //from the connected socket.emit event function updateFunction(newJSON) { //do whatever with new JSON data } </code></pre> <p>This is assuming there is some external endpoint being accessed to update JSON; having it come from a client over socket.io would simply involve defining another event, but this time having it <code>emit</code> from the client, and be listened to by the server.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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