问题描述
在广播消息部分中 http://socket.io/docs/#broadcasting-messages 有以下说明
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.broadcast.emit('user connected');
});
广播是一个对象.为什么文档说明将其称为标记
The broadcast is an object. Why does the doc description refers it as flag
推荐答案
在socket.io实现的内部,broadcast
是一个标志,该标志随emit发送,告诉底层基础结构该怎么做.请参阅该标记的来源,您可以在此处在源中查看为套接字上的该标志确定是否应广播给定的emit
.
Internally in the socket.io implementation, broadcast
is a flag that is sent with an emit that tells the underlying infrastructure what to do. See the source for that flag here and you can see here in the source where it tests for that flag on a socket to decide if a given emit
should be broadcast.
socket.broadcast.emit()
中的broadcast
确实是一个对象.
The broadcast
in socket.broadcast.emit()
is indeed an object.
broadcast
也是socket.io内部使用的适配器对象上的方法.因此,他们几乎将所有术语(标志,对象,方法)都使用了该术语.在您引用的情况下,该文档有一些不同的用法.
broadcast
is also a method on the adapter object which is used internally by socket.io. So, they've used the term for just about everything (flag, object, method). The doc has a few of the different uses confused in the case you reference.
socket.io文档就是它的样子(不尽如人意).我发现在Github上不断引用源代码,甚至在调试器中追溯执行对于理解事物的工作方式都是必不可少的.
The socket.io doc is what it is (not nearly as good as it could be). I find constant references to the source code on Github or even tracing into the execution in a debugger to be essential for understanding how things work.
这篇关于当广播实际上是一个对象时,为什么在文档中将广播描述为标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!