我有SignalR與Angular客戶端一起工作,但如果在訂閱事件之前建立了連接,我無法使proxy.on()
工作。在連接到服務器啓動後,SignalR不使用'on'訂閱
我的服務器方法在兩個集線器上調用客戶端方法pushToClient
。
var connection1 = $.hubConnection(); //Works fine since I started connection AFTER subscribing
var proxy1 = connection1.createHubProxy('clientPushHub');
proxy1.on('sendToClient', function (message) {
console.log('This will work: ' + message);
});
connection.start();
var connection2 = $.hubConnection(); // Won't work when I subscribe BEFORE starting connection
var proxy2 = connection2.createHubProxy('clientPushHub');
connection2.start();
proxy2.on('sendToClient', function (message) {
console.log('This will not work: ' + message);
});
如果我改變的事情,這樣開始connection2
之前proxy2
訂閱了pushToClient,它工作正常。還嘗試在start()。done()回調中執行'on'訂閱,但那不起作用。
我已經下載並驗證this example作品如我所料訂閱後當連接,並this ASP.NET article/section特別提到,你可以做的事情在這個順序,如果你不使用生成的代理,我卻沒有。
在this SO question中提問者的工作對我不起作用。
任何想法,我可能會出錯?
適用於我。另外,感謝您指出文章中的片段。我錯過了它的原因是我在看註冊聽衆的部分,它說你可以在開始後進行。我沒有想到通過開始一段時間,我回頭看了一張便條。 – gilm0079