Why do we require to put socket.on
inside socket.on
here? What does this represent? Is there any other way of writing this?
This is the code of server.js in nodejs.
var objExpress = require('express')()
var objHttp = require('http').createServer(objExpress)
var objSocketIO = require('socket.io')(objHttp)
objExpress.get('/', (request, result) => result.send('hello'))
objSocketIO.on('connection', (argSocket) => {
console.log('A user connected!');
argSocket.on('message', (argMsg) => {
console.log(argMsg);
argSocket.broadcast.emit('message-broadcast-xyz', argMsg)
})
})
objHttp.listen(3000, () => {
console.log("Listening on port 3000")
})