【发布时间】:2015-05-22 08:22:52
【问题描述】:
我正在使用 signalR 2.1.2,我正在向我的客户推送通知。 前端是负载平衡的。 奇怪的是:有时有效,有时无效。似乎与浏览器的类型没有任何关系。有时它可以在 IE 中运行,有时它可以在 Chrome 中运行。首先我认为传输类型可能是问题,这就是为什么我将传输类型降级为长轮询,不幸的是它没有帮助:
客户端:
$.connection.hub.logging = true; // Enable SignalR logging
$.connection.hub.start({ transport: 'longPolling' }).done(function() {
console.log("Connected, using transport method: " + $.connection.hub.transport.name);
}).fail(function() {
console.log("ERROR! Could not establish SignalR connection");
});
$.connection.hub.stateChanged(function(change) {
if (change.newState === $.signalR.connectionState.disconnected) {
console.log("State of SignalR connection changed to disconnected");
} else if (change.newState === $.signalR.connectionState.connected) {
console.log("State of SignalR connection changed to connected");
}
});
$.connection.MessageHub.client.newIncoming = function(id) {
// server call and that stuff
}
服务器端:
[HubName("MessageHub")]
public class MessageNotificationHub : Hub
{
// Methods that are implemented here, can be called by the client via ajax and broadcast to every other client
public override Task OnConnected()
{
return base.OnConnected();
}
}
在服务器上:
public void Notify(long id)
{
var notifyHubContext = GlobalHost.ConnectionManager.GetHubContext<MessageNotificationHub>();
notifyHubContext.Clients.All.newIncoming(id);
}
没什么大不了的,只是看起来像另一个 signalR 样本。
以下是日志中的错误消息:
SignalR:客户端订阅了集线器“messagehub”。 SignalR:正在与 '/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22messagehub%22%...进行协商...
错误!无法建立 SignalR 连接
SignalR:停止连接。
SignalR 连接状态更改为断开连接
解码 URI 显示: https://server/applicationname/signalr/negotiate?clientProtocol=1.4&connectionData=[{"name":"messagehub"}]&_=1426756354570
有没有可能是负载均衡部分导致了我所有的麻烦。
感谢您的帮助! 谢谢
【问题讨论】: