SignalR组没有得到数据 [英] SignalR Groups not getting data

查看:469
本文介绍了SignalR组没有得到数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题在我的signalR客户谁是一组没有得到发送的信息。

我在两种方式尝试这样做,都无法正常工作。

在网页加载客户端将调用服务器来获得的组名,然后调用集线器上的方法加入该组中的用户。

JavaScript的.....

  VAR connectionOpen = FALSE;
        VAR myHub;
        $(函数(){
            myHub = $ .connection.myHub;
            myHub.client.showMessage = alertMessage;
            $ .connection.hub.start(函数(){
                connectionOpen = TRUE;
                加入组();
            });
        });        功能joinGroup(){
            $阿贾克斯({
                网址:控制器/ GetGroupName,
                输入:POST,
                成功:函数(集团){
                    如果(connectionOpen ==真)
                        tileHub.server.joinGroup(组);
                }
            });
        }功能alertMessage(字符串值){
警报(值);
}

控制器

  [HttpPost]
公共JsonResult GetGroupName()
{
    返回JSON(富);
}

myHub

 公共无效JoinGroup(串组名)
{
    Groups.Add(Context.ConnectionId,组名);
}

我已经通过code无数次踩到我可以看到我连接好,并加入该组织,但是当我尝试发送回组没有任何反应。

我用这从我的控制器发送到组

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

这是我已经尝试了第二种方式,我也试图从轮毂发送到组,但仍然没有喜悦。

任何帮助将大大AP preciated ...

更新
此问题已修复感谢大卫·福勒....

这是一个错误,由于这样的事实,我用的是HubName属性给集线器不同的名称,然后signalR使用longPolling运输。删除属性允许该知道的工作。一个修复程序也有规定请参阅 https://github.com/SignalR/SignalR/issues/1039


解决方案

几件事情:


  1. 请务必阅读重新加入组部分对这个职位。的http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx.

  2. 你真的需要进行Ajax调用从服务器计算出的组名?你不能只在页面直接呈现呢?

  3. 是否失败,如果你硬code富作为组名无处不在?

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

解决方案

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?

这篇关于SignalR组没有得到数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆