Why has my webpage lost the ability to receive signalr messages

I basically have 3 applications. A web application, Nservicebus and a signalr self-hosting server for my hubs. I am currently using the signalr.4 version. Basically, a web application initiates a connection to a standalone server when the page loads. The user performs an action that sends a command to the service bus. The service bus then connects to the signalr server to notify all web clients.

My webpage:

<script src="http://localhost:8081/test/signalr/hubs" type="text/javascript"></script>
<script>
    jQuery.support.cors = true;
    var myHub;  

    $.connection.hub.url = 'http://localhost:8081/test/signalr/hubs';

    $(function () {
        myHub = $.connection.userAccountHub;

        myHub.ChangeNameUpdated = function (connId) {
            alert("recieved signalr message");          
        };

        $.connection.hub.start().done(function() {
            var myClientId = $.connection.hub.id;
            setCookie("srconnectionid", myClientId);
        });
    });

</script>

My SignalR Server:

      static void Main(string[] args)
    {
        Debug.Listeners.Add(new ConsoleTraceListener());
        Debug.AutoFlush = true;

        string url = "http://localhost:8081/test/";
        var server = new Server(url);


        server.EnableHubs();
        server.Start();


        Console.WriteLine("Server running on {0}", url);

        while (true)
        strong text{
            ConsoleKeyInfo ki = Console.ReadKey(true);
            if (ki.Key == ConsoleKey.X)
            {
                break;
            }
        }
    }

My hub inside my Signalr server

 public class UserAccountHub : Hub
    {

        public void UsersNameChanged(string passedThroughConnectionId)
        {
            Clients.ChangeNameUpdated(passedThroughConnectionId);
        }
    }

My call from my nservicebus

        //connect to signalRServer
        var connection = new HubConnection("http://localhost:8081/test/signalr/hubs");
        IHubProxy myHub = connection.CreateProxy("SignalRServer.Hubs.UserAccountHub");

        //Credentials are inherited from the application
        connection.Credentials = CredentialCache.DefaultNetworkCredentials;

        var test = message.GetHeader("signalrConnectionId");


        connection.Start().Wait();
        myHub.Invoke("UsersNameChanged", message.GetHeader("signalrConnectionId")).ContinueWith(task =>
        {
            //for debuging purposes
            if (task.IsFaulted)
            {
                Console.WriteLine(
                    "An error occurred during the method call {0}",
                    task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Successfully called MethodOnServer");
            }
        });

I open 2 browsers. I run the process in the second browser, and only the first receives notifications. The second browser does not.

I do not see the problems that stand out when starting the violinist.

, - ?

+3
1

OK! , . , , . -

1.) .5

2.) javascript

$.connection.hub.url = 'http://localhost:8081/test/signalr';

$.connection.hub.start({ transport: 'longPolling', xdomain: true }).done(function () {
    //alert("staring hub connection:  " + $.connection.hub.id);
    setCookie("srconnectionid", $.connection.hub.id);
});

3.) HubConnection

var connection = new HubConnection("http://localhost:8081/test/");

4.) IHubProxy

IHubProxy myHub = connection.CreateProxy("UserAccountHub");
+2

All Articles