2012-02-16 41 views
6

我使用signalr 0.4一个aspx页上,Signalr停止了几分钟后做回调

var hub = $.connection.FooHub; 

hub.disconnected(function() {     
      log("Server has disconnected"); 
     }); 

hub.ShowInfo = function (Info) { .... } 

$("#Button1").click(function() { 
      hub.FooFunction('foo'); 
     }); 

$.connection.hub.start(); 

集线器的定义为:

public class FooHub : Hub, IDisconnect 
{  
    ~FooHub() 
    { 
     log.Debug("FooHub Destroy"); 
    } 
    public FooHub() 
    { 
     log.Debug("FooHub Startup"); 
    }  
    public bool FooFunction(string stuff) 
    { 
     log.Debug("Hub FooFunction"); 
     Clients.ShowInfo(someInfo); 
     return true; 
    } 
    public Task Disconnect() 
    { 
     // Query the database to find the user by it's client id etc. etc. 
     MyController.Disconnect(Context.ConnectionId); 
     log.Debug("Hub Disconnnect " + Context.ConnectionId); 
     return null; 
    } 
    ...... 
} 

当我打开网页,并立即点击按钮1
它调用Hub,然后调用页面上的ShowInfo函数。
随着Firebug我可以看到,信号使用长轮询为通信。因此,一切都按预期工作。

但是,当我再等几分钟
我看到

  • FooHub被破坏
  • 断开是所谓的枢纽,

但页面上没有新的连接
Firebug显示仍在执行的旧的
当我然后点击按钮 -

  • FooFunction叫(我看到在萤火一个新的连接)
  • FooHub创建
  • FooFunction在中心执行(没有在日志线)
  • ,但不执行ShowInfo

这是SignalR中的一个错误,还是我必须做别的事情才能获得ShowInfo调用?

更新(可能的答案):

将其使用永远帧,而不是长轮询。

此外,问题似乎主要发生在使用移动互联网(usb-stick)和Firefox时。

将交通工具更改为长轮询似乎解决了这个问题。

回答

1

你提到切换到长轮询而不是使用永远的框架,但没有说如何做到这一点。您可以指定在启动连接时尝试使用哪些传输。

connection.start({ transport: ['longPolling','webSockets'] }); 

有关更多选项,请参阅https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client