本文介绍了SignalR - HubContext和Hub.Context的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来signalR和阅读API和玩弄它。有点困惑集线器和它的语境。

I am new to signalR and reading the API and playing around with it. a bit confused about the Hub and its Context.

这就是 Hub.Context 不是 HubContext

HubContext 我可以从 GlobalHost.ConnectionManager.GetHubContext&LT获得; THub>()

Hub.Context 给我一个 HubCallerContext 这我不知道怎么用。

and Hub.Context gives me a HubCallerContext which I am not sure how to use.

他们有什么关系?我怎样才能获得 HubContext从中心集线器从HubContext

What are their relationship? How can I get HubContext from Hub or Hub from HubContext ?

推荐答案

命名不良的结果。 Hub.Context是从呼叫者(更像一个请求上下文)的HTTP上下文。该HubContext有GroupManager并映射到Hub.Groups和Hub.Clients客户端。

A result of poor naming. Hub.Context is the http context from the caller (more like a request context). The HubContext has the GroupManager and Clients which map to Hub.Groups and Hub.Clients.

您可以添加到组并从轮毂外面聊到客户端。
在轮毂内,你可以得到呼叫者的连接ID并获得与枢纽调用相关的HTTP请求上下文。轮毂之外,你不能做Context.Clients.Caller或Context.Clients.Others,因为当你在轮毂外没有来电显示。

You can add to groups and talk to the client from outside the hub.Inside the hub you can get the connection id of the caller and get the http request context associated with the hub invocation. Outside of the hub, you can't do Context.Clients.Caller or Context.Clients.Others because there's no caller when you're outside of the hub.

。希望清除的东西了。

这篇关于SignalR - HubContext和Hub.Context的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:08