如何解决这个问题?没看懂,求大神帮忙,谢谢 这是我运行 node server.js 时的错误消息:
client.on('getRelay', function (state) { ReferenceError: client is not defined
var express = require ('express');
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = 3000;
let bodyRelay = {
relayId: 'RELAY-123',
state: 1
}
app.use(express.static(__dirname + '/node_modules'));
app.get('/', function(req, res, next) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(client) {
console.log('a user has connected');
});
io.sockets.emit('setRelay', bodyRelay);
client.on('getRelay', function (state) {
bodyRelay = state;
console.log('id: ' + client.id + 'bodyRelay: ' + JSON.stringify(bodyRelay));
// io.sockets.emit('setRelay', bodyRelay);
});
client.on('disconnect', function() {
console.log('a user has disconnected');
});
server.listen(port, () => {
console.log('Server is running on port: ' + port)
});