locked
SignalR Connection Refused RRS feed

  • Question

  • User-1396731495 posted

    Hello Everybody

    I'm using signalr for first time,

    I have a c# console application (server) and an mvc application (client)

    My Client Side Connection Code;

    <script type="text/javascript" src="~/Scripts/jquery.signalR-2.2.3.js"></script>
            <script src="http://localhost:53453/signalr/hubs"></script>
            <script>
                var sure = 2000;
                $(document).ready(function () {
    
                    $.connection.hub.url = "http://localhost:53453/signalr";
                    var chat = $.connection.Server;
                    $.connection.hub.start().done(function () {
                        chat.server.baglan("@Session["id"]");
                    });
    });
    </script>

    My server side code block

                string url = "http://localhost:53453";
                using (WebApp.Start(url))
                {
                    Console.WriteLine("SignalR Server running on {0}", url);
                    Console.Read();
                }

    Startup.cs

    public void Configuration(IAppBuilder app)
            {
                app.UseCors(CorsOptions.AllowAll);
                app.MapSignalR();
            }

    Server.cs(HUB)

    [HubName("Server")]
        public class Server:Hub
        {
            public void baglan(string uid)
            {
                string userid = uid;
    
            }
        }

    When I run the website I get these errors.Please help me to fix it.

    GET http://localhost:53453/signalr/hubs net::ERR_CONNECTION_REFUSED

    jquery.signalR-2.2.3.js:247 Uncaught Error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/js'></script>.
    at Object.start (jquery.signalR-2.2.3.js:247)
    at HTMLDocument.<anonymous> (Panel:29)
    at fire (jquery-1.10.2.js:3062)
    at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
    at Function.ready (jquery-1.10.2.js:447)
    at HTMLDocument.completed (jquery-1.10.2.js:118)

    Thursday, March 29, 2018 12:23 PM

Answers

  • User-1396731495 posted

    Thanks for your help.

    I've fixed my error with changing this

    using (WebApp.Start(url))
                {
                    Console.WriteLine("SignalR Server running on {0}", url);
                    Console.Read();
                }

    to

    WebApp.Start(url)
    
    Console.WriteLine("SignalR Server running on {0}", url);
    
    Console.Read();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 31, 2018 3:50 PM

All replies

  • User1325410084 posted

    Is your hub really named "Server"?    var chat = $.connection.Server;

    Even if so, note that unless you decorated it with the HubName attribute, specifying the name as "Server", the first letter will be made lowercase "server" in the JS proxy.  And that's how you would reference it there.

    It will behave the same way with any server methods you might be trying to call as well.

    Thursday, March 29, 2018 7:32 PM
  • User-1396731495 posted

    Thanks for your help.

    I've fixed my error with changing this

    using (WebApp.Start(url))
                {
                    Console.WriteLine("SignalR Server running on {0}", url);
                    Console.Read();
                }

    to

    WebApp.Start(url)
    
    Console.WriteLine("SignalR Server running on {0}", url);
    
    Console.Read();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 31, 2018 3:50 PM