简单发射的套接字和 volatile 发射的套接字有什么区别?
What is the difference between a socket that simply emits and one that volatile emits?
这是下面问题的后续问题;
在下面的代码中,套接字使用 volatile 来发射。
var updateSockets = function(data) {
// adding the time of the last update
data.time = new Date();
console.log('Pushing new data to the clients connected ( connections amount = %s ) - %s', connectionsArray.length , data.time);
// sending new data to all the sockets connected
connectionsArray.forEach(function(tmpSocket) {
tmpSocket.volatile.emit('notification', data);
});
};
如果将代码更改为 tmpSocket.emit('notification', data);
怎么办? tmpSocket.volatile.emit('notification', data);
和 tmpSocket.emit('notification', data);
有什么区别?
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 they’re connected through
long polling and is in the middle of a request-response cycle), if
they 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 来发射。
var updateSockets = function(data) {
// adding the time of the last update
data.time = new Date();
console.log('Pushing new data to the clients connected ( connections amount = %s ) - %s', connectionsArray.length , data.time);
// sending new data to all the sockets connected
connectionsArray.forEach(function(tmpSocket) {
tmpSocket.volatile.emit('notification', data);
});
};
如果将代码更改为 tmpSocket.emit('notification', data);
怎么办? tmpSocket.volatile.emit('notification', data);
和 tmpSocket.emit('notification', data);
有什么区别?
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 they’re connected through long polling and is in the middle of a request-response cycle), if they 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.
本质上,如果您不关心客户端是否收到数据,则将其作为易失性发送。