0
votes

In the SignalR tutorial here: http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host

    static void Main(string[] args)
    {
        // This will *ONLY* bind to localhost, if you want to bind to all addresses
        // use http://*:8080 to bind to all addresses. 
        // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
        // for more information.
        string url = "http://localhost:8080";
        using (WebApp.Start(url))
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }
    }

When do I bind only to localhost and when do I choose to bind to all addresses?

I'm finding it strange because I specified localhost on both my server and client.

This is my client code hosted as a windows service

            var hubConnection = new HubConnection("http://localhost:8080/");
            IHubProxy hubProxy = hubConnection.CreateHubProxy("MyHub");
            hubProxy.On<string, string>("addMessage", (name, message) =>
            {
                Log.Info(string.Format("Incoming data: {0} {1}", name, message));
            });
            ServicePointManager.DefaultConnectionLimit = 10;
            await hubConnection.Start();

The client works when my server is binded to all address

string url = "http://*:8080";

If I bind only to localhost, my client doesn't receive any messages from the server.

1

1 Answers

0
votes

Are you running the client and server on the same machine? If not, 'localhost' won't work. Try using the machine name instead.