如何在一个页面上安装多个SignalR集线器 [英] How to have multiple SignalR hub on one page

查看:112
本文介绍了如何在一个页面上安装多个SignalR集线器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SignalR集线器管理一种类型的消息传递。我需要在同一页面添加第二个集线器,这只是一个消息发布并返回到其他客户端并发布消息。

I've one SignalR hub that manages one type of messaging. I need to add a second hub to the same page which is just a post a message and returns to the rest of the clients and a posted message.

是否可以一个连接有多个集线器?这笔交易是如果一个集线器在其他集线器之前启动,如果第一个集线器已经开始连接,我如何连接或订阅当前集线器?

Is it possible to have multiple hubs for one connection? The deal is that if one hub is started before the others how do I connect or subscribe to the current hub if the first hub has already started the connection?

它们都是消息类型的集线器,但可以使用一个或多个。

They are both a messaging type of hub but one many or may be used.

我如何处理这个?

< a href =http://www.AlumCloud.Com =nofollow> AlumCloud

推荐答案

要为一个页面设置多个集线器,您不需要执行任何特殊操作,只需创建另一个集线器类。

To have multiple hubs for one page you do not need to do anything special, just create another hub class.

确保您可以从集线器接收消息您已经在开始连接之前为集线器注册了客户端方法。

To ensure that you can receive messages from a hub in general ensure that you have registered a client side method for the hub prior to starting your connection.

因此,如果您想使用多个集线器,您需要做的就是拥有客户端在开始连接之前要订阅的集线器的方法。

Therefore, if you want to use multiple hubs, all you need to do is have client methods for the hubs you want to subscribe to prior to starting your connection.

无论您订阅了多少个集线器,它们都使用一个非常好的连接:) 。

No matter how many hubs you are subscribed to they all use one connection which is pretty nice :).

要解决在连接启动后想要订阅集线器的问题,您不能。另一种方法是始终订阅两个集线器并使用组来控制数据的发送位置。您可以在此处了解有关群组的更多信息: http://www.asp。 net / signalr / overview / signalr-20 / hubs-api / working-with-groups

To address your issue of wanting to "subscribe" to a hub after the connection is started, you can't. An alternative would be to always subscribe to both hubs and use groups to control where data is sent. You can learn more about groups here: http://www.asp.net/signalr/overview/signalr-20/hubs-api/working-with-groups

这篇关于如何在一个页面上安装多个SignalR集线器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆