在新的 socket.io v0.7 中,有一个新功能“ volatile 消息”。
在“如何使用”中,他们这样写:(在http://socket.io/#how-to-use)
Sending volatile messages.
Sometimes certain messages can be dropped. Let's say you have an app that shows realtime >tweets for the keyword
bieber
.If a certain client is not ready to receive messages (because of network slowness or other >issues, or because he's connected through long polling and is in the middle of a request- >response cycle), if he doesn't receive ALL the tweets related to bieber your application >won't suffer.
In that case, you might want to send those messages as volatile messages.
我认为 volatile 有点不一致,所以为什么他们告诉我们应该使用 volatile 消息作为我们不能错过的消息类型?默认消息呢?我必须怎么做才能确保消息到达客户端?
另外,我还想问一下xhr-multipart transport。我在 v0.7 的传输列表中没有看到它。被删除了吗?
最佳答案
就像它通常所说的那样,socket.io 会跟踪它收到的消息,如果我的用户错过了一条消息,它将再次发送。如果您不想要这种开销(额外的工作),您可以使用 volatile 消息,但代价是用户可能会错过消息。如果您还想按顺序收到消息,可以使用确认(回调)=>
服务器:
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.on('ferret', function (name, fn) {
fn('woot');
});
});
客户:
<script>
var socket = io.connect(); // TIP: .connect with no args does auto-discovery
socket.on('connection', function () {
socket.emit('ferret', 'tobi', function (data) {
console.log(data); // data will be 'woot'
});
});
</script>
我也找不到 xhr-multipart,但我想如果你真的想知道你可以问 Guille?
关于node.js - 任何人都可以向我解释 socket.io/nodejs 中的 "volatile"消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523942/