为什么我们需要放在socket.on这里socket.on?这代表什么?还有其他写法吗?
这是nodejs中server.js的代码。
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")
})
BIG阳
相关分类