5

Hi I am having a problem where my signalR clients who are in a group do not get the information sent.

I have tried this in two ways and both not working.

On web page loaded the client will call the server to get the group name and then call a method on the hub to join the user in that group.

JavaScript.....

        var connectionOpen = false;
        var myHub;
        $(function () {
            myHub = $.connection.myHub;
            myHub.client.showMessage = alertMessage;
            $.connection.hub.start(function () {
                connectionOpen = true;
                joinGroup();
            });
        });

        function joinGroup() {
            $.ajax({
                url: 'Controller/GetGroupName,
                type: 'POST',
                success: function (group) {
                    if (connectionOpen == true)
                        tileHub.server.joinGroup(group);
                }
            });
        }

function alertMessage(string value){
alert(value);
}

Controller

[HttpPost]
public JsonResult GetGroupName()
{
    return Json("Foo");
}

myHub

public void JoinGroup(string groupName)
{
    Groups.Add(Context.ConnectionId, groupName);
}

I have stepped through the code numerous times and I can see that I am connecting ok and joining the group but when I try and send back to the group nothing happens

I am sending to the group using this from my controller

GlobalHost.ConnectionManager.GetHubContext<myHub>().Clients.Group("Foo").showMessage("Hello");

This is the second way I have tried, I have also tried sending to the groups from the hub but still no joy.

any help would be greatly appreciated...

Updated This has been fixed thanks to David Fowler....

This was a bug due to the fact that I was giving the Hub a different name using the HubName attribute and then signalR using the longPolling transport. Removing the attribute allows this to know work. A fix has also been provided please see https://github.com/SignalR/SignalR/issues/1039

2 Answers 2

3

Few things:

  1. Make sure you read the "Rejoining Groups" section on this post. http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx.
  2. Do you really need to make an ajax call to figure out the group name from the server? Can't you just render it directly in the page?
  3. Does it fail if you hardcode "Foo" as the group name everywhere?
9
  • Thanks for the response. I have read the information about rejoining groups and added the EnableAutoRejoiningGroups() into Global with no change. I need to get the group over an ajax call as they leave and re-join different groups over the session that they are active. I have tested hard coding the group Foo bypassing the server call with the same results. I have created a working sample in another project but I cant for the life of me see what the differences are between the two.
    – jclarkson
    Nov 26, 2012 at 16:56
  • After another day of investigations I have found the difference between the working sample project I created and the one I am having problems with is that the latter is using the transport protocol - longpolling. If I change the working project to use long polling I get the same result (no calls received by members in a group). Is this by design or a bug? I have tried to force the offending project to use websockets but it just defaults back to long polling.
    – jclarkson
    Nov 28, 2012 at 9:30
  • 1
    That's why I brought up EnableAutoRejoiningGroups, that's the difference and the blog post describes in detail why that is.
    – davidfowl
    Nov 28, 2012 at 9:52
  • I have added this into the Application_Start method in Global.cs but still no changes could there be anything else I am missing?
    – jclarkson
    Nov 28, 2012 at 11:14
  • 1
    Note: EnableAutoRejoiningGroups was removed from release 1.0.0. See details here
    – Dror
    Mar 13, 2013 at 0:05
0

Found in the anwser of dfowler: https://github.com/SignalR/SignalR/issues/1039 < Didn't see it in de comments.

The solution is: Remove the HubName attribute from your Hub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.