I am new to socket.io and have realized that every server-side eventlistenrs are wrapped in a io.on connection block:
io.on('connection', socket => {
socket.on('event name', callback)
})
I am a little confused about two things:
- do I always have to wrap my
socket.onin this kind of blocks? Is it because thesocketrepresents the individual client that raised the connection event? - Why should I use
socket.oninside the block instead ofio.onsince they seem to do the same thing(likeio.on('connection', () => io.on('event name', callback)))?