title: Signalr - Join multiple groups
body: <p>Edit: David Fowler requested for the full code to attempt to replicate the problem. Here is the full code</p>
  
  <p>In addition to the code reproduced here, I have also uploaded a complete Visual Studio 2010 solution to the following URL</p>
  
  <p><a href="http://www.sendspace.com/file/lfeurf" rel="nofollow">http://www.sendspace.com/file/lfeurf</a> (URL has now expired and no longer works)</p>
  
  <p>Please feel free to download and test it.</p>
  
  <p>Here are my findings</p>
  
  <ol>
  <li>Adding only one group in the Hub code will make the application work
  fine with no problems</li>
  <li>Adding 2 groups will either stop signalr from
  working or will work in one direction only. ie: the message will be
  transmitted from browser 1 to browser 2 but will not be transmitted
  from browser 2 to browser 1</li>
  </ol>
  
  <p>Original question:
  I am using Signalr 1.0.0-rc1 in a MVC3 website. My clients sometimes need to belong to multiple groups. Here is the code in my Hub and client side javascript</p>
  
  <p>Client side javascript and HTML</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      //start signalr
      var message = $.connection.messageHub;
  
      // Declare a function on the message hub so the server can invoke it          
      message.client.send = function (message) {
          alert(message);
      }
  
      // Start the connection and join groups
      $.connection.hub.start();
  
      //bind click event of button to invoke send function on server
      $(document).ready(function () {
          $("#target").click(function () {
              message.server.send("Hello from signalr");
          });
      });
  &lt;/script&gt;
  
  &lt;button id="target"&gt;Click to send message to other clients&lt;/button&gt;
  </code></pre>
  
  <p>Server side Hub</p>
  
  <pre><code>public class MessageHub: Hub
      {
          public Task AddGroups()
          {
              //add 1st group
              Groups.Add(Context.ConnectionId, "foo");
              //add 2nd group
              return Groups.Add(Context.ConnectionId, "foobar");
          }
  
          //this method will be called from the client
          public void Send(string message)
          {
              Clients.OthersInGroup("foobar").send(message);
          }
  
          //automatically join groups when client first connects
          public override Task OnConnected()
          {
              return AddGroups();
          }
  
          //rejoin groups if client disconnects and then reconnects
          public override Task OnReconnected()
          {
              return AddGroups();
          }
  
      }
  </code></pre>
  
  <p>The above code should add two groups to each client when they first connect but it does not work. I stepped through the C# code using a debugger and no errors are being thrown. I also dont see any javascript errors using Chrome's console but the Send function is not being called on the clients. I then changed the AddGroups() method to add only one group as shown below</p>
  
  <pre><code>public Task AddGroups()
     {
          //dont add first group
          //Groups.Add(Context.ConnectionId, "foo");
          //add only second group
          return Groups.Add(Context.ConnectionId, "foobar");
     }
  </code></pre>
  
  <p>Now my application works perfectly. How do I add a second group? It looks like I have misunderstood joining multiple groups. Could anyone show me the right way to do it?</p>