SignalR: не удается подключиться к http://localhost:8080 автономный сервер, использующий полный IP-адрес



Я создаю автономный сервер Signal R, используя следующий код:



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);
}
}
}


Я также создал несколько клиентских приложений, подключающихся к этому серверу SignalR через концентратор, и все работает нормально, когда я тестирую на своем локальном компьютере.



Но когда я пытаюсь подключиться к серверу, используя IP-адрес компьютера домена или имя компьютера вместо http://localhost:8080 (с другого компьютера доменной сети или даже с моего локального компьютера), я получаю ошибку, так как сервер не может находиться.

Не могли бы вы помочь мне подключиться к моему серверу SignalR, используя IP-адрес вместо "localhost"?

459   2  

2 ответов:

Решение было следующим:

  1. Установка url сервера в http://{MyIPAddress}:8080 вместо http://localhost:8080
  2. открытие порта 8080 путем добавления нового правила TCP inbound в Брандмауэре Windows

Вы можете использовать это для автоматической установки вашего IP:

 <script src="http://<%=Request.ServerVariables("LOCAL_ADDR")%>:8080/signalr/hubs"></script>

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

Comments

    Ничего не найдено.