我正在尝试使用SignalR创建一个聊天应用程序。为了能够发送私人消息,我想将客户端分配到一个具有其profileID名称的组。所以我可以简单地调用组的addMessage函数来发送到特定的客户端。
当我转到此页面时:
https://github.com/SignalR/SignalR/wiki/Hubs
它告诉我向Hub添加一个名为Join()的函数。在这里,我可以将独立客户端添加到一个组中。所以我创建了这个代码:
[HubName("Chat")]
public class ChatHub : Hub
{
public Task Join()
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
Profiel_DataHelper profiel = new Profiel_DataHelper(HttpContext.Current.User.Identity.Name);
return Groups.Add(Context.ConnectionId, profiel.ProfielID.ToString());
}
else
{
return null;
}
}
.....
当我想调用特定的客户端时,我会使用以下代码:
var context = GlobalHost.ConnectionManager.GetHubContext();
context.Clients.Group(profielidNaar).addTyptOnline(profielidVan);
但当我运行程序时,Join()Task根本没有被调用,因此我对组的调用也不起作用。
我做错了什么?