How to have multiple SignalR concentrators on one page

I have one SignalR hub that controls one type of messaging. I need to add a second hub to the same page, which is only a message and returns to the other clients the published message.

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

They are a type of messaging, but one of them or can be used.

How do I approach this?

Alumcloud

+3
source share
1 answer

To have multiple hubs for one page, you don’t have to do anything, just create another hub class.

So that you can receive messages from the hub as a whole, be sure to register the client side method for the hub before starting your connection.

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

No matter how many nodes you are subscribed to, they all use the same connection, which is pretty nice :).

To eliminate the problem associated with the need to "subscribe" to the hub after starting the connection, you will not be able to. An alternative would be to always subscribe to both hubs and use groups to control the sending of data. You can learn more about groups here: http://www.asp.net/signalr/overview/signalr-20/hubs-api/working-with-groups

+6
source

Source: https://habr.com/ru/post/975576/


All Articles