2014-03-04 133 views
0

在SignalR教程這裏:http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-hostSignalR:綁定本地主機VS中的所有地址

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"; 

的客戶端的工作,我的客戶沒有按」不接收來自服務器的消息。

回答

0

您是否在同一臺計算機上運行客戶端和服務器?如果沒有,'localhost'將不起作用。嘗試使用機器名稱。

+0

是的,它是同一臺機器。 –