Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR on Home Network

Edit/Summary

After a lot of trial and error, Paul Kearney - pk helped lead me to the answer, although I still don't know why this happens, at least I know how to get it to work.

Quick Summary: Clients can connect to port 8080 on my laptop when I'm directly connected to my network at work. Clients cannot connect to port 8080 when I'm on a home network. To solve this, I created a firewall rule (on my laptop) to allow inbound traffic on 8080. I'd really like to know why this is the case. Does my laptop's Windows Firewall service actually change its settings based on the network I'm connected to?


Note: This all works when I'm on my network at work, but it doesn't work on my home network, or someone else's home network. The host computer (my laptop) is the same at both locations.

I have a web app that uses SignalR. Everything works when I run the web app on the same machine as where the SignalR host is running. When I try to connect from a different machine, I get this error:

> GET http://10.0.0.13:8080/signalr/hubs net::ERR_CONNECTION_TIMED_OUT. Cannot read property 'client' of undefined.

That error comes from my index.html page:

<script src="http://10.0.0.13:8080/signalr/hubs"></script>

From the research that I've done, I know that I shouldn't be using localhost in my SignalR URL. So I used an asterisk. This is in my self-hosted SignalR app:

class Program
{
    static void Main(string[] args)
    {
        string url = "http://*:8080";
        using (WebApp.Start(url))
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }
    }
}

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR();
    }
}
public class RaceHub : Hub
{
    public void Send(string name, string message)
    {
        Clients.All.addMessage(name, message);
    }
}

And this is my JavaScript to connect:

  var signalRUrl = 'http://10.0.0.13:8080/signalr';

  $.connection.hub.url = signalRUrl;
  var hub = $.connection.raceHub;  // proxy reference to hub

  // Create a function that the hub can call to broadcast messages.
  hub.client.addMessage = function (name, message) {
      receiveSignalRMessage(name, message);
  };

  $.connection.hub.start();  // Start the connection.

Like I said, this all works locally. But it doesn't work from another machine. I do not have Windows Firewall enabled, so that's not the issue. Any ideas?

HTTPS didn't work. It works when I'm on my network at work, but not at home. The configuration is the same. Must have something to do with my home network.

Also, this is what the page looks like when it's working properly:

enter image description here

And this is what happens when it's not working:

enter image description here

like image 522
Bob Horn Avatar asked Oct 20 '22 10:10

Bob Horn


1 Answers

(Full disclosure - @BobHorn typed up this answer based on my comments)

There are different firewall settings on your machine, depending on the type of network you are attached to.

Have you ever noticed when you connect to a new network for the very first time, it asks you to define it as "work, private, public, home, etc"?

Whatever you choose for that network is sticky, and the related firewall policy is applied when you are on that type of network.

To check this, you can either completely turn off your firewall, or make sure inbound port 8080 is open for all firewall profiles, especially "home" networks and/or the "home" firewall profile.

ahh.. so you say your windows firewall is off. Are you sure it's not OFF only for the WORK network profile, but enabled for the HOME network profile ?

To troubleshoot this, I would put wireshark on one of the client computers trying to connect to port 8080 at home, and see how/why it's being blocked or cannot connect.

You can also try to telnet to port 8080 from the client machine at home (if the Telnet Client feature is enabled). You'll know right away if the port is open and connection succeeds, or a big fat denied. Quick and easy test. type TELNET ServerIPAddress PortNumber from a command line. If Telnet command not found, you need to turn on the Telnet Client in Windows Features/Components.

like image 107
Paul Kearney - pk Avatar answered Oct 23 '22 01:10

Paul Kearney - pk