我正在尝试通过socket.io刷新html页面。因此,我想在服务器端更改后调用刷新功能。目前我只是通过测试来做到这一点。但目前我不知道我如何能够访问 io.on之外的 <连接&#39; ...
dpylr
测试:
const express = require('express');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var clientSocket;
module.exports.startConnection = function () {
io.on('connection', function (socket){
clientSocket = socket;
});
http.listen(8001, function (){
console.log('listening on *:8001');
});
};
module.exports.refresh = function () {
clientSocket.emit('refresh');
};