Signalr 能否连接到位于不同主机/服务器上的集线器?

Signalr 能否连接到位于不同主机/服务器上的集线器?,signalr,signalr-hub,Signalr,Signalr Hub,假设我在www.website.com上有一个网站。我与signalr的SaaS托管在www.signalr.com上 我可以从www.website.com连接到www.signar.com signar服务器吗 而不是: var connection = $.hubConnection(); var contosoChatHubProxy = connection.createHubProxy('contosoChatHub'); 比如: var connection = $.hubCon

假设我在www.website.com上有一个网站。我与signalr的SaaS托管在www.signalr.com上

我可以从www.website.com连接到www.signar.com signar服务器吗

而不是:

var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');
比如:

var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('www.signalr.com/contosoChatHub');
简短回答:是的-

第一步是在服务器上启用跨域。现在,您可以启用来自所有域的调用,也可以只启用来自指定域的调用。()

下一步是配置客户端以连接到特定域

使用生成的proxy(),您可以通过以下方式连接到名为
TestHub
的中心:

 var hub = $.connection.testHub;
 //here you define the client methods (at least one of them)
 $.connection.hub.start();
现在,您只需指定服务器上配置SignalR的URL。(基本上是服务器)

默认情况下,如果不指定它,则假定它与客户端是同一个域

`var hub = $.connection.testHub;
 //here you specify the domain:

 $.connection.hub.url = "http://yourdomain/signalr" - with the default routing
//if you routed SignalR in other way, you enter the route you defined.

 //here you define the client methods (at least one of them)
 $.connection.hub.start();`

应该是这样。希望这有帮助。祝你好运

我发现以下内容非常有用:

你成功了吗?我明天会试试,谢谢:)
`var hub = $.connection.testHub;
 //here you specify the domain:

 $.connection.hub.url = "http://yourdomain/signalr" - with the default routing
//if you routed SignalR in other way, you enter the route you defined.

 //here you define the client methods (at least one of them)
 $.connection.hub.start();`