SignalR - HubContext and Hub.Context

I am new to signalR and read the API and play with it. a little confused in the hub and its context.

That is Hub.Contextnot HubContext.

HubContext I can get from GlobalHost.ConnectionManager.GetHubContext<THub>()

and Hub.Contextgives me HubCallerContextwhich I am not sure how to use.

What is their relationship? How can i get HubContext from Hubor Hub from HubContext?

+5
source share
2 answers

The result of poor naming. Hub.Context- This is the HTTP context from the caller (more similar to the request context). HubContexthas GroupManagerand Clientswhich are displayed on Hub.Groupsand Hub.Clients.

. HTTP-, . Context.Clients.Caller Context.Clients.Others , .

, .

+7

HubCallerContext - , . HubContext:

public class MyHub : Hub
{        
    public void Foo()
    {               
        // These two are equivalent
        Clients.Caller.bar();
        Clients.Client(Context.ConnectionId).bar(); // Context.ConnectionId is the client that made the request connection id
    }
}

, HubContext, , . Caller Context.ConnectionId.

, , HubContext HubCallerContext.

HubCallerContext , HubContext.

HubContext , - .

, !

+6

All Articles