socket.on('connection' … event never fired nodejs + express + socket.io

前端 未结 3 717
遥遥无期
遥遥无期 2020-12-29 09:15

Problem socket.io NOT working

Details

  • Generated a project with express [folder]; cd [folder]; npm install;
3条回答
  •  抹茶落季
    2020-12-29 09:56

    Took a while to notice... the connection event is emmited on io.sockets. In your code this would be

    socket.sockets.on('connection', function (client) {
      client.send("hello")
      console.log("hello", client)
    })
    

    You should use io instead of socket as the var name to avoid this confusion.

提交回复
热议问题