SignalR不能用于远程连接
本文关键字:远程连接 用于 不能 SignalR | 更新日期: 2023-09-27 17:51:01
我正在一个使用signalr的网站上工作,当我在本地机器上测试它时,它工作得很好,但是当我远程尝试它时,我无法浏览mvc,当我尝试发送信号请求时,它只是坐在那里等待。
这是我的javascript代码(我使用angularjs,但所有的代码工作得很好!):
function FixturesListController($scope,$q) {
$scope.fixtures = [''];
var stringListHub = $.connection.stringListHub,
model = {
Items: []
};
$.connection.hub.url = "http://192.168.1.2:8001/signalr";
stringListHub.client.updateModel = function(newName) {
if (newName.Items != null) {
$scope.$apply(function() {
$scope.fixtures.length = 0;
$(newName.Items).each(function(index, value) {
$scope.fixtures.push(value);
});
});
}
}
$.connection.hub.start({ xdomain: true }).done(function () {
var fixtures = stringListHub.server.test().done(function (item) {
$scope.$apply(function () {
if (item.Items != null) {
$scope.fixtures.length = 0;
$(item.Items).each(function(index, value) {
$scope.fixtures.push(value);
});
}
});
});
});
$scope.AddFixture = function() {
$scope.fixtures.push($scope.newName);
stringListHub.server.updateModel({
Items: $scope.fixtures
});
};
}
信号集线器:
public class StringListHub : Hub
{
private static StringList _list = new StringList();
public void UpdateModel( StringList model )
{
_list = model;
_list.LastUpdatedBy = Context.ConnectionId;
// Update the shape model within our broadcaster
Clients.AllExcept( _list.LastUpdatedBy ).updateModel( _list );
}
public StringList Test()
{
return _list;
}
}
我把这个添加到我的web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
我发现了问题所在。我在我自己的机器上进行了测试,iis将最大并发连接数限制为3。所以我在windows服务器上运行它,它工作得很好。