我已使用以下内容设置我的服务器:
const socket = require('socket.io');
// Start the app by listening on <port>
const server = http.createServer(app);
const io = socket(server);
server
.listen(config.port)
.on('connection', (socket) => {
console.log('A client is connected!');
socket.setTimeout(30 * 1000);
});
// Expose app
exports = module.exports = app;
此时&#39;客户已连接&#39;多次记录并初始化套接字。但是,当我尝试使用套接字发送这样的事件时:
const io = require('../../../server').io;
io.on('connection', (socket) => {
socket.emit('verified');
});
产生以下错误:
'TypeError: Cannot read property \'on\' of undefined'
这与node v 4.2.2完美配合,但是,我们现在已升级到6.11.3并收到此错误。
任何帮助?