2016-10-11 140 views
0

在我SignalR客戶端,我有以下的JavaScript庫:SignalR僅適用於本地主機

<!--Reference the jQuery library. --> 
<script src="Scripts/jquery-1.6.4.min.js"></script> 
<!--Reference the SignalR library. --> 
<script src="Scripts/jquery.signalR-2.2.1.min.js"></script> 
<!--Reference the autogenerated SignalR hub script. --> 
<script src="http://localhost:8081/signalr/hubs"></script> 

在JavaScript我去:

$.connection.hub.url = "http://localhost:8081/signalr; 
$.connection.hub.logging = true; 
var push = $.connection.exosChangeNotifier; 
... 
$.connection.hub.start().done(); 

連接本地主機與效果很好。 當我在虛擬機上或另一臺計算機上運行我的SignalR樞紐,並與IP地址或計算機名替換本地主機,我得到一個

http://[servername]:8081/signalr/hubs Failed to load resource: the server responded with a status of 400 (Bad Request) 
Uncaught TypeError: Cannot read property 'client' of undefined. 

我打開了8081端口的防火牆在我的電腦上傳出規則和遠程計算機或虛擬機上的進入規則。隨着Sysinternal psping我驗證該端口是否可達:

psping.exe [servername]:8081 -h 

隨着Powershell Script我能仔細檢查計算機能訪問和端口是開放的。

在自託管SignalR啓動已啓用了CORS:

map.UseCors(CorsOptions.AllowAll); 

我缺少什麼?

+0

您是否也在服務器上使用端口8081? – Ted

+0

是的。 8081用於服務器和客戶端。否則,當我在本地使用它時,它不起作用。 – tobre

+0

看來,你只需要找出正確的網址,這是沒有人在外面可以幫助你... – Ted

回答

0

我在this SO Question找到了解決方案。服務器必須以http:// *:8081開始響應內部和外部請求。在它被設置爲只聽本地主機之前。

相關問題