How does Node socket.io actively push messages to the front end?

how do node and socket.io take the initiative to send messages to the front end

I use node to read data from the database, and send new data directly to the front end. Because the database is sometimes updated several times in a minute, node reads it and sends it out.

the foreground user can just leave the page open

now users have to send an event to the backend

how to solve

Thank you

Mar.03,2021

have you finished reading the document? https://socket.io/get-started. uses broadcast (Broadcasting).


Direct io.emit is sent to all clients connected to the default namespace


io.on('connection', function (socket) {
    socket.emit('event', function (data, callback) {
        //event
    })
    socket.broadcast.emit('event', function (data, callback) {
        //event
    })
    io.emit('event', function (data, callback) {
        //event
    })
    io.to(sockedID).emit('event', function (data, callback) {
        //event
    })
}
Menu