0
我正在使用SignalR构建一个ASP Web表单多人游戏平台来更新游戏领域。如何在Hub子类中获取组?
我有GameHub
是处理新的播放器连接:
[HubName("GameHub")]
public class GameHub : Hub
{
static protected IHubContext context = GlobalHost.ConnectionManager.GetHubContext<GameHub>();
static public Dictionary<string, string> connectionIds_sessions = new Dictionary<string, string>();//connectionId and sessionId
public void JoinGroup(string sessionId)
{
//this is called when the page is opened
string connectionId = Context.ConnectionId;
connectionIds_sessions.Add(connectionId, sessionId);
Groups.Add(connectionId, sessionId);
}
}
而且我对每个游戏的子类。例如ThisHub
:
[HubName("TrisHub")]
public class TrisHub : GameHub
{
public void SendTrisUpdates(string sessionId, TrisSession tris)
{
Clients.Group(sessionId).getUpdates(tris);//here I receive System.NullReferenceException.
}
}
我不能从母体类GameHub创建,因为没有组送东西。
我该怎么办?
所以我不能有一个母亲班Hub? –
你可以。但他们将彼此独立(自己的连接,自己的团体等)。 – MaKCbIMKo