2

如果我有一个 signalR 集线器向具有相当大的有效负载或私有信息的所有客户端发送消息,那么连接到集线器(同一组的一部分)的所有客户端是否都会收到消息,即使它们没有订阅这些事件客户端?

想知道客户端是否足够聪明,可以与服务器协商它有哪些事件,以便服务器不会发送无关数据?

谢谢!

4

1 回答 1

5

是的,他们这样做。如果客户端订阅了一个集线器,它将接收通过该集线器的广播频道发送的所有消息。

除了发送到不包括该客户端的特定组或专门发送到另一个客户端之外,没有其他方法可以阻止客户端获取消息。

一些例子:

Clients.All.foo(); // All subscribed clients will foo invoked
Clients.Group("bar").foo(); // All subscribed clients to the hubs group "Bar" will have foo invoked.  If your client is not subscribed to "bar" it will not have "foo" invoked.
Clients.Client("AClientsConnectionId").foo(); // The client with the specified connection id will have foo invoked.
于 2013-06-07T22:33:36.197 回答