【发布时间】:2018-05-15 17:51:25
【问题描述】:
我正在尝试制作 SignalR 服务器和客户端架构,在该架构中我可以连接到“http://localhost:8080”或http://127.0.0.1:8080/,但我无法连接我的本地 IP 地址,例如“192.x.x.x”,所以可以有理由吗? 请帮助我,我也将我的代码放在这里...
public partial class WinFormsServer : Form
{
private IDisposable SignalR { get; set; }
const string ServerURI = "http://localhost:8080";
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();
}
}
}
【问题讨论】:
标签: asp.net-mvc c#-4.0 server signalr signalr-hub