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
    })
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c537-2c2f9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c537-2c2f9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?