SignalR: unable to connect to http: // localhost: 8080 self-hosted server using full IP address

I create my own Signal R server using the following code:

internal class Config { internal static string serverurl = null; internal static Microsoft.AspNet.SignalR.HubConfiguration hubconfiguration = null; internal static SignalRHub Hub { get; set; } internal static void StartServer() { serverurl = "http://localhost:8080"; // In this method, a web application of type Startup is started at the specified URL (http://localhost:8080). { Microsoft.Owin.Hosting.WebApp.Start<Startup>(serverurl); Log.AddMessage("Server running on " + serverurl); } catch(Exception ex) { Log.AddMessage("An error occurred when starting Server: " + ex); } } } class Startup { // the class containing the configuration for the SignalR server // (the only configuration is the call to UseCors), // and the call to MapSignalR, which creates routes for any Hub objects in the project. public void Configuration(IAppBuilder app) { try { app.UseCors(CorsOptions.AllowAll); // Enable detailed errors when an exception occures Config.hubconfiguration = new HubConfiguration(); Config.hubconfiguration.EnableDetailedErrors = true; app.MapSignalR("/signalr", Config.hubconfiguration); } catch(Exception ex) { Log.AddMessage("An error occurred during server configuration: " + ex.Message); } } } 

I also created several client applications connecting to this SignalR server through a hub, and everything works fine when I test on my local computer.

But when I try to connect to the server using the IP address of a domain computer or the computer name instead of http://localhost:8080 (from another computer on the domain network or even from my local computer), I get an error message as the server was not found.

Could you help me connect to my SignalR server using the IP address instead of "localhost"?

+5
source share
2 answers

Decision:

  • Setting the server url http://{MyIPAddress}:8080 instead of http://localhost:8080
  • Opening port 8080 by adding a new TCP input rule in the Windows Firewall
+5
source

You can use this to automatically set your IP:

  <script src="http://<%=Request.ServerVariables("LOCAL_ADDR")%>:8080/signalr/hubs"></script> $.connection.hub.url = "http://<%=Request.ServerVariables("LOCAL_ADDR")%>:8080/signalr"; 
0
source

Source: https://habr.com/ru/post/1200670/


All Articles