• 00
  • :
  • 00
  • :
  • 00

Signalr

后台内部发送到指定客户端

Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<tvHub>().Clients.Client(Client.Key).sendMessage(UserHandler.dicGoods[roomid]);

  

 var lst = UserHandler.getRoomInfoListByRoomID(roomid);
                    foreach (var Client in lst)
                    {
                        //GlobalHost.ConnectionManager.GetHubContext<tvHub>().Clients
                        GlobalHost.ConnectionManager.GetHubContext<tvHub>().Clients.Client(Client.Key).sendMessage(UserHandler.dicGoods[roomid]);
                        //Clients.Client(Client.Key).sendMessage(UserHandler.dicGoods[roomid]);
                    }

 

 

winform链接

 

Connection = new HubConnection(ServerURI);
HubProxy = Connection.CreateHubProxy("wgHub");

try
{
await Connection.Start();
}

catch //(Exception ex)
{
}

 

链接绑定用户ID

  //声明静态变量存储当前在线用户
    public static class UserHandler
    {
        public static Dictionary<string, SNInfo> ConnectedIds = new Dictionary<string, SNInfo>();
    }

 

     //用户进入页面时执行的(连接操作)
        public void controllerConnected(string sn, string guid)
        {
            //进行编码,防止XSS攻击
            sn = HttpUtility.HtmlEncode(sn);

            //新增目前使用者上线清单
            UserHandler.ConnectedIds.Add(Context.ConnectionId, new SNInfo(sn, guid));
        }

 

posted @ 2016-12-03 14:29  Garson_Zhang  阅读(321)  评论(0编辑  收藏  举报