zoukankan      html  css  js  c++  java
  • Asp.Net SignalR Hub类中的操作详解

    Asp.Net SignalR Hub类中的操作详解

     

    Hub类中的操作

    在服务端我们要通过Hub类做一系列操作,下面就说说我们都可以做什么操作

    客户端的发送消息操作

    image

    调用所有的客户端的helloClient方法

    Clients.All.helloClient();

    调用除了给定ConnectionId的客户端之外的所有客户端的helloClient方法

    Clients.AllExcept(Context.ConnectionId).helloClient();

    调用指定的connectionId的客户端的helloClient方法

    Clients.Client(Context.ConnectionId).helloClient();

    给指定的ConnectionId集合的客户端调用helloClient方法

    Clients.Clients(new List<string>() {"client1", "client2"}).helloClient();

    调用指定名称的群组中的所有客户端helloClient方法, 此方法有重载,可以指定排除的ConnectionId

    Clients.Group("room1").helloClient();

    调用指定群组集合的所有客户端的helloClient方法,此方法有重载,可以指定排除的ConnectionId

    Clients.Groups(new List<string>() {"room1", "room2"}).helloClient();

    群组操作

    还记得在持久连接类中可以往群组中添加组员和删除组员,在集线器中也是可以做到的。

    image

    添加操作

    Groups.Add(this.Context.ConnectionId, "room1");

    删除操作

    Groups.Remove(this.Context.ConnectionId, "room1");

    注:Clients中的User和Users没有进行讲解,因为涉及到身份验证,留到之后博文再进行讲解

  • 相关阅读:
    springMVC+spring+mybatis整合(包括文件上传和下载)
    mybatis spring 框架整合
    Java AOP 注解配置与xml配置
    Java 实现分页功能
    Arcanist安装使用流程
    Swift 添加KVO
    swift 混编OC instanceType 标识的方法找不到
    Swift UIStackView代码使用
    Swift
    swift 相册PHAssetCollection,PHAsset
  • 原文地址:https://www.cnblogs.com/zxtceq/p/7567516.html
Copyright © 2011-2022 走看看