Bob Horn
Bob Horn

Reputation: 34315

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

Upvotes: 5

Views: 3009

Answers (4)

Paul Kearney - pk
Paul Kearney - pk

Reputation: 5543

(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.

Upvotes: 3

Brian Driscoll
Brian Driscoll

Reputation: 19635

I believe the issue here is that your laptop's IP address changes from one network (i.e. work) to another (i.e. home), but you may not be updating the value of the signalRUrl variable in your javascript file accordingly, thus the client side of your app is looking for a hub at an IP address that doesn't exist on your home network.

When you change networks, you need to update the value of signalRUrl in javascript to reflect the current IP address of the host machine.

Upvotes: 0

Matt
Matt

Reputation: 35261

It looks like your work network is blocking your IP. Try whitelisting your home IP on your work network.

Upvotes: 0

Patrick Fletcher
Patrick Fletcher

Reputation: 284

Does your network use IP security? You might try using HTTPS instead to see if that alleviates anything.

Upvotes: 0

Related Questions