1

I'm running a server with a localhost http://*:52080. On the same computer, I'm run client and trying to connect to a local IP hub http://192.168.1.102:52080/signalr. Everything works well.

But if I run the client on another computer (from the same local network) and try to connect to http://192.168.1.102:52080/signalr, it does not connect. The client catches an exception ("System.AggregateException" in mscorlib.dll).

Port 52080 on the computer with the hub is open.

What could be the reason for the failure?

Server:

using System;
using Microsoft.Owin.Hosting;

public class Program
{
    static void Main(string[] args)
    {
        string url = "http://*:52080";
        using (WebApp.Start<Startup>(url))
        {
            Console.WriteLine("Server running at {0}\n", url);
            Console.ReadLine();
        }
    }
}

Startup.cs

using Owin;
using Microsoft.Owin.Cors;

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

SGHub.cs

using System;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using System.Collections.Generic;

public class SGHub : Hub
{   
    public static List<string> Users = new List<string>();

    public override Task OnConnected()
    {
        Console.WriteLine("\nOnConnected {0}", Context.ConnectionId);
        Users.Add(Context.ConnectionId);

        Clients.Caller.broadcastMessage("Server:", "Successful connection");
        Clients.Others.broadcastMessage("Server:", "New connection");

        return (base.OnConnected());
    }
}

Client:

using System; 
using Microsoft.AspNet.SignalR.Client; 
using Microsoft.AspNet.SignalR.Client.Hubs; 
using Newtonsoft.Json.Linq; 

class Program
{
    static void Main(string[] args)
    {
        string serverURL = "http://192.168.1.102:52080/signalr";

        Console.WriteLine("Connection to {0}\n", serverURL);
        HubConnection hubConnection = new HubConnection(serverURL);
        IHubProxy myHubProxy = hubConnection.CreateHubProxy("StartGameHub");

        myHubProxy.On<string, string>("Send", (name, message) => Console.Write("Recieved addMessage: " + name + ": " + message + "\n"));
        myHubProxy.On("heartbeat", () => Console.Write("Recieved heartbeat \n"));

        Subscription subscription = myHubProxy.Subscribe("broadcastMessage");
        subscription.Received += SubscriptionData;

        while (true)
        {
            string key = Console.ReadLine();

            if (key.ToUpper() == "A")
            {
                try
                {
                    Console.WriteLine("Start connect..");
                    hubConnection.Start().Wait();
                }
                catch (System.AggregateException e)
                {
                    Console.WriteLine("Connected fauld :(");
                }
            }
        }
    }

    private static void SubscriptionData(IList<JToken> obj)
    {
        Console.WriteLine(obj[1].ToString());
    }
}
mason
  • 31,774
  • 10
  • 77
  • 121
zRirez
  • 109
  • 2
  • 10
  • Firewall blocking external connections to the port? – zmechanic Mar 15 '17 at 13:08
  • In the firewall for incoming connections, I set the rule for port `52080` and allowed connections. – zRirez Mar 15 '17 at 13:14
  • So, what your `AggregateException` actually tells you? – zmechanic Mar 15 '17 at 13:17
  • is the server hosted on IIS? – MistyK Mar 15 '17 at 13:23
  • System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: it is impossible to connect to the remote server ---> System.Net.Sockets.SocketException: the connection attempt failed because another desired computer did not receive the desired response within the required time or the connection is already established. Violated from For the wrong answer of the computer already connected 192.168.1.102:52080 In System.Net.Sockets.Socket.EndConnect (IAsyncResult asyncResult) – zRirez Mar 15 '17 at 14:02
  • In System.Net.ServicePoint.ConnectSocketInternal (Boolean connectFailure, Socket S4, Socket S6, Socket & socket, IP address and address, the ConnectSocketState state, IAsyncResult asyncResult, exception and exception) --- End of internal stack trace of exceptions --- – zRirez Mar 15 '17 at 14:03
  • Server isn`t hosted on IIS. – zRirez Mar 15 '17 at 14:04
  • This is the same as http://stackoverflow.com/questions/42790435/signalr-server-hosting-localhost – Pawel Mar 15 '17 at 16:57

1 Answers1

2

The problem wasn`t in the code and the implementation method, but in the banal glitch of the router, after it rebooted and rebooted all computers (just in case) everything worked.

zRirez
  • 109
  • 2
  • 10