SignalR:无法连接到任何IP地址

时间:2017-07-10 09:16:30

标签: c# localhost signalr signalr-hub signalr.client

我尝试使用带有IP地址的SignalR,但我无法连接任何IP地址。首先,我尝试了服务器URI。 " http://127.0.0.1:8080/signalr"但我有些错误。客户端应用说无法连接服务器。这可能是什么原因?

public partial class WinFormsServer : Form
{
    private IDisposable SignalR { get; set; }
    const string ServerURI = "http://localhost:8080/signalr";

    private void ButtonStart_Click(object sender, EventArgs e)
    {
        WriteToConsole("Starting server...");
        ButtonStart.Enabled = false;
        Task.Run(() => StartServer());
    }

    private void StartServer()
    {
        try
        {
            SignalR = WebApp.Start(ServerURI);
        }
        catch (TargetInvocationException)
        {
            WriteToConsole("Server failed to start. A server is already running on " + ServerURI);
            //Re-enable button to let user try to start server again
            this.Invoke((Action)(() => ButtonStart.Enabled = true));
            return;
        }
        this.Invoke((Action)(() => ButtonStop.Enabled = true));
        WriteToConsole("Server started at " + ServerURI);
    }

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

我用Rick van den Bosch解决的代码改变了我的启动课程。但我仍然无法连接任何IP地址。

public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Map("/signalr", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration { };
                map.RunSignalR(hubConfiguration);
            });
        }
    }

0 个答案:

没有答案