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)); }
慎于行,敏于思!GGGGGG