2.3.4. Add Or Remove Connection From Groups

  • 1.Create a join method in hub:

          public void join(string group)
          {
              //join group
              Groups.Add(Context.ConnectionId, group);
              //remove group
              //Groups.Remove(Context.ConnectionId, group);
          }
  • 2.Call join method in client side:

                      $.connection.hub.start().done(function () {
                          obj.server.join(g);
                          $("#send").click(function () {
                              obj.server.servermethod($("#name").html(), $("#msg").val());
                              console.log($("#msg").val());
                       });

Last updated