Why SignalR cannot connect across machines?

Aspire 81 Reputation points
2023-11-21T03:07:40.89+00:00

I have a C# .NET Framework client and server, and I use SignalR to make them communicate. When I deploy the client and server in the same machine, they can make connection well, but if I move the client to another machine, it can never connect to the server and it return the error

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.224.10.10:12345

I have already added the port 12345 into Inbound Rule with Local port = 12345, Protocol type = TCP.

Client side code

//Create a connection for the SignalR server
_signalRConnection = new  HubConnection("http://10.224.10.10:12345/signalr/SimpleHub/"); 
  
//Get a proxy object that will be used to interact with the specific hub on the server 
//There may be many hubs hosted on the server, so provide the type name for the hub 
_hubProxy = _signalRConnection.CreateHubProxy("SimpleHub");

Server side code

using Microsoft.Owin.Hosting; 
using Microsoft.AspNet.SignalR; 
using System.ComponentModel;  
namespace WinFormsServer 
{     
    public partial class FrmServer : Form     
    {         
        private IDisposable _signalR;         
        private void btnStartServer_Click(object sender, EventArgs e)         
        {             
            try             
            {                 
                //Start SignalR server with the give URL address                         
                //Final server address will be "URL/signalr"                     
                //Startup.Configuration is called automatically                 
                _signalR = WebApp.Start<Startup>("http://*:12345/");                 
                writeToLog($"Server started at:{txtUrl.Text}");             
            }             
            catch (Exception ex)             
            {                 
                MessageBox.Show(ex.Message, "Error",         
                MessageBoxButtons.OK, MessageBoxIcon.Error);             
            }         
        }     
    } 
}
using Owin; 
using Microsoft.Owin.Cors;  
namespace WinFormsServer 
{     
    class Startup     
    {         
    public void Configuration(IAppBuilder app)         
    {             
        //CORS need to be enabled for calling SignalR service
        app.UseCors(CorsOptions.AllowAll);             
        //Find and reigster SignalR hubs
        app.MapSignalR();         
    }     
    } 
}
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,180 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
120 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,270 questions
{count} votes