你将如何在下面两个发射之间引入延迟:
var app = require('http').createServer();
var io = require('socket.io')(app);
app.listen(8092);
io.on('connection', function (socket) {
socket.emit('foo', ["data1"]);
socket.emit('foo', ["data2"]);
});
我想创建一个简单的服务器模拟器,它可以在不同的时间点输出数据。
答案 0 :(得分:1)
你试过这个:
var app = require('http').createServer();
var io = require('socket.io')(app);
app.listen(8092);
io.on('connection', function(socket) {
socket.emit('foo', ["data1"]);
setTimeout(() => {
socket.emit('foo', ["data2"]);
}, 1500); // change the 1500 to whatever time delay you want in milliseconds
});