簡體   English   中英

SignalR無法用於遠程連接

[英]SignalR not working for remote connections

我在一個使用signalr的站點上工作,當我在本地計算機上對其進行測試時,它工作正常,但是當ai遠程嘗試它時,我無法瀏覽mvc,並且當我嘗試向Signalar發送請求時,它就坐在那兒等待。

這是我的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服務器上運行了它,並且工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM