SignalR停止后谈判,不ping通,连接或作出任何长轮询XHR请求 [英] SignalR stops after negotiate, doesn't ping, connect or make any long polling XHR requests

查看:1462
本文介绍了SignalR停止后谈判,不ping通,连接或作出任何长轮询XHR请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SignalR 1.1.2与SQL作为底板,并经常(如页面加载的70%),洽谈请求SignalR火灾并​​suceedes(不会失败),只是停止并没有任何反应了。我发现有一个与jquery.validation.js有些抵触
所以我更新:jQuery的,jQuery验证和jQuery不显眼的阿贾克斯以最新可用的版本,但它仍然发生,,

其他的时候,它工作正常,我可以看到一些XHR请求提出:


  • 洽谈


  • 连接



  • 长轮询请求进一步

下面是我的枢纽:

 公共类NotificationsHub:集线器
{
    公众覆盖任务OnConnected()
    {
       Groups.Add(Context.ConnectionId,CurrentUser.UserId.ToString());
       返回base.OnConnected();
    }    公众覆盖任务OnDisconnected()
    {
        Groups.Remove(Context.ConnectionId,CurrentUser.UserId.ToString());
        返回base.OnDisconnected();
    }
   }

和我的客户code:

  $(文件)。就绪(函数(){
    变种NH = $ .connection.notificationsHub;
    nh.notify =功能(notificationHtml){
        $('#通知盒')找到(UL)prePEND(notificationHtml)。
        $('#通知气泡)文字($('#通知气泡)文字()+ 1);
    };    $ .connection.hub.start();
});

虽然提神页我得到错误:

 来的连接http://localhost:55087/signalr/connect?transport=serverSentEvents&connectionToken=FuqvvQJaxyCfy0dj2DEoZQFkBmthBk9LxU6ZEGZO4ypbSy8pUpzrvCKWTjykxp9E9GtMdwLI0sX_tWkvK1XfJaEtjFHOL3Qmeg2eILh4pTZnEzXDyq6KPuvPw_4kzj9VtNe89YsWW-3sstPwu_I60A2&connectionData=%5B%5D&tid=4而页面加载被中断。

,然后按照其succedes POST请求:

<$p$p><$c$c>http://localhost:55087/signalr/abort?transport=serverSentEvents&connectionToken=FuqvvQJaxyCfy0dj2DEoZQFkBmthBk9LxU6ZEGZO4ypbSy8pUpzrvCKWTjykxp9E9GtMdwLI0sX_tWkvK1XfJaEtjFHOL3Qmeg2eILh4pTZnEzXDyq6KPuvPw_4kzj9VtNe89YsWW-3sstPwu_I60A2

这里是速战速决,但我想知道这是一个错误或SignalR的正常行为:

<一个href=\"http://stackoverflow.com/questions/15782281/signalr-event-becomes-intermittent-when-deployed-to-a-server\">SignalR当部署到服务器事件变得断断续续

更新2:

从上面的修复工作,但长轮询XHR请求持续了几分钟,这似乎奇数给我,当要求compleated这是不能接受几分钟后,客户端进行了更新,所以我决定SignalR升级到2.0.0 Beta2的

这是第一次后,我正在运行(后秒钟左右超时)SignalR无法连接应用程序..
第二次一切运行良好,长轮询XHR是在2秒完成了上衣。
第三次回踩人,没有平,无connnect,没有长轮询请求。但是,当事情从服务器端触发它得到像它通过连接的WebSockets的immedietly更新..和只有我能在调试窗口中看到的事情是:

[○时12分52秒GMT + 0200(中欧标准时间)] SignalR:客户端触发事件枢纽枢纽上的'通知'NotificationsHub

下面是我到集线器改变它与SignalR工作2.0.0 Beta2的

 公共类NotificationsHub:集线器
    {
         公共异步替代任务OnConnected()
         {
             VAR用户= WebSecurity.GetUserId(Context.User.Identity.Name);
             Groups.Add(Context.ConnectionId,user.ToString());
             伺机base.OnConnected();
         }        // OnDisconnected()滴感谢N.泰勒·马伦
    }

客户端:

  $(文件)。就绪(函数(){
    $ .connection.notificationsHub.client.notify =功能(notificationHtml){
        $('#通知盒')找到(UL)prePEND(notificationHtml)。
        $('#通知气泡)文字(parseInt函数($('#通知气泡)文字())+ 1);
    };    $ .connection.hub.logging = TRUE; //可选的,如果你想看看是怎么回事
    $ .connection.hub.start();
});


解决方案

您连接中断,应通过重新连接事件解决。不过这似乎并没有发生。你有一些问题,集线器,修改为:

 公共类NotificationsHub:集线器
{
    公众覆盖任务OnConnected()
    {
        //确保该集团完成OnConnected前加入
       返回Groups.Add(Context.ConnectionId,CurrentUser.UserId.ToString());
    }    //切勿在OnDisconnected组中删除,的ConnectionId的是自动移除组时断开连接。
}

I am using SignalR 1.1.2 with SQL as backplane, and frequently (like 70% of page loads), SignalR fires of negotiate request which suceedes (doesn't fail) and just halts and nothing happens anymore. I found out that there is some conflict with jquery.validation.js so I updated: jquery, jquery validation and jquery unobtrusive ajax to latest available versions, but it still happens,,

Other times when it works correctly I can see few XHR requests made:

  • negotiate

  • connect

  • ping

  • long polling requests further on

Here is my hub:

public class NotificationsHub : Hub
{
    public override Task OnConnected()
    {
       Groups.Add(Context.ConnectionId, CurrentUser.UserId.ToString());
       return base.OnConnected();
    }

    public override Task OnDisconnected()
    {
        Groups.Remove(Context.ConnectionId, CurrentUser.UserId.ToString());
        return base.OnDisconnected();
    }
   }

And my client code:

$(document).ready(function () {
    var nh = $.connection.notificationsHub;
    nh.notify = function (notificationHtml) {
        $('#notification-box').find('ul').prepend(notificationHtml);
        $('#notification-bubble').text($('#notification-bubble').text() + 1);
    };

    $.connection.hub.start();
});

While refreshing page I get error:

The connection to http://localhost:55087/signalr/connect?transport=serverSentEvents&connectionToken=FuqvvQJaxyCfy0dj2DEoZQFkBmthBk9LxU6ZEGZO4ypbSy8pUpzrvCKWTjykxp9E9GtMdwLI0sX_tWkvK1XfJaEtjFHOL3Qmeg2eILh4pTZnEzXDyq6KPuvPw_4kzj9VtNe89YsWW-3sstPwu_I60A2&connectionData=%5B%5D&tid=4 was interrupted while the page was loading.

And then following POST request which succedes:

http://localhost:55087/signalr/abort?transport=serverSentEvents&connectionToken=FuqvvQJaxyCfy0dj2DEoZQFkBmthBk9LxU6ZEGZO4ypbSy8pUpzrvCKWTjykxp9E9GtMdwLI0sX_tWkvK1XfJaEtjFHOL3Qmeg2eILh4pTZnEzXDyq6KPuvPw_4kzj9VtNe89YsWW-3sstPwu_I60A2

Here is a quick fix, but I would like to know is this a bug or normal behaviour of SignalR:

SignalR event becomes intermittent when deployed to a server

Update 2:

Fix from above worked but long poll XHR requests lasted for few minutes, which seemed odd to me and client side was updated after few minutes when request compleated which isn't acceptable, so I decided to upgrade SignalR to 2.0.0 beta2.

After that first time I was running applications SignalR couldn't connect(timeout after second or so).. Second time everything worked fine, long poll XHR were completing in 2 sec tops. Third time back to step one, no ping, no connnect, no long poll requests. BUT when something is triggered from server side it get's updated immedietly like it is connected through websockets.. and only thing I can see in debug window is:

[00:12:52 GMT+0200 (Central European Standard Time)] SignalR: Triggering client hub event 'notify' on hub 'NotificationsHub'.

Here are my changes to Hub which work with SignalR 2.0.0 beta2

 public class NotificationsHub : Hub
    {
         public async override Task OnConnected()
         {
             var user = WebSecurity.GetUserId(Context.User.Identity.Name);
             Groups.Add(Context.ConnectionId, user.ToString());
             await base.OnConnected();
         }

        // OnDisconnected() was dropped thanks to N. Taylor Mullen
    }

Client side:

$(document).ready(function () {
    $.connection.notificationsHub.client.notify = function (notificationHtml) {
        $('#notification-box').find('ul').prepend(notificationHtml);
        $('#notification-bubble').text(parseInt($('#notification-bubble').text()) + 1);
    };

    $.connection.hub.logging = true; // optional, if you want to see what's going on 
    $.connection.hub.start();
});

解决方案

Your connection interruption should be resolved by a reconnect event. However that doesn't seem to be happening. You have some issues in your Hub, modify it to be:

public class NotificationsHub : Hub
{
    public override Task OnConnected()
    {       
        // Ensure that the group is added before completing OnConnected
       return Groups.Add(Context.ConnectionId, CurrentUser.UserId.ToString());
    }

    // Never remove from group in OnDisconnected, ConnectionId's are auto-removed from groups when they disconnect.
}

这篇关于SignalR停止后谈判,不ping通,连接或作出任何长轮询XHR请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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