socket.io with express

后端 未结 4 866
借酒劲吻你
借酒劲吻你 2021-02-01 07:44

i have a project and I\'m using socket.io with express ,

so what i need (i tried) is broadcasting a message but from an express action. is this possible i don\'t know ho

4条回答
  •  广开言路
    2021-02-01 08:20

    You might want to have a look at my socket.io + Express primer. What you want is covered in detail there.

    // Send to all connected sockets
    io.sockets.send('Hello, World!');
    
    // Send to all sockets in a specified room
    io.sockets.in('room').send('Hello, Room!');
    

    Where io is the value returned by the call to socketio.listen(). You can place that code anywhere in your application, eg in your app.get callbacks.

提交回复
热议问题