【发布时间】:2014-03-04 05:47:19
【问题描述】:
在 SignalR 教程中:http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host
static void Main(string[] args)
{
// This will *ONLY* bind to localhost, if you want to bind to all addresses
// use http://*:8080 to bind to all addresses.
// See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
// for more information.
string url = "http://localhost:8080";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
}
}
什么时候只绑定到本地主机,什么时候选择绑定到所有地址?
我觉得这很奇怪,因为我在服务器和客户端上都指定了localhost。
这是我作为 Windows 服务托管的客户端代码
var hubConnection = new HubConnection("http://localhost:8080/");
IHubProxy hubProxy = hubConnection.CreateHubProxy("MyHub");
hubProxy.On<string, string>("addMessage", (name, message) =>
{
Log.Info(string.Format("Incoming data: {0} {1}", name, message));
});
ServicePointManager.DefaultConnectionLimit = 10;
await hubConnection.Start();
当我的服务器绑定到所有地址时,客户端工作
string url = "http://*:8080";
如果我只绑定到本地主机,我的客户端不会收到来自服务器的任何消息。
【问题讨论】: