SignalR客户具有多个连接 [英] SignalR client with multiple connections

查看:780
本文介绍了SignalR客户具有多个连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个SignalR服务运行,只有一个UI来访问它们。

I have multiple SignalR 'services' running and only one UI to access them.

我怎样才能使客户端的js去跟不同的网址多个连接?因为它似乎我只能指定每个$ .connection.hub一个网址,我不能使用多个'signalr /枢纽的客户端脚本。

How can I make the client js to talk to multiple connections with different Url? Because it seems I can only specify one url per $.connection.hub, and I can't use multiple 'signalr/hubs' client scripts.

任何帮助吗?谢谢你。

推荐答案

$。connection.hub在/ signalr /集线器包含创建的。

$.connection.hub is created in the /signalr/hubs inclusion.

目前它本质上是做文件的末尾:

At the end of the file it essentially does:

$.connection.hub = $.hubConnection("/signalr", { useDefaultPath: false });

要创建你做的枢纽代理:

To create the hub proxy you do:

var myHub = $.connection.hub.createHubProxy('myHub');

对多个连接的简单的例子:

Simple example for multiple connections:

var connection1 = $.hubConnection("http://www.myfirstendpoint.com");
var connection2 = $.hubConnection("http://www.mysecondendpoint.com");

var myCon1Hub = connection1.createHubProxy('myCon1Hub');
var myCon2Hub = connection2.createHubProxy('myCon2Hub');

myCon1Hub.client.foo = function() { ... Whatever you want ... };
myCon2Hub.client.foo = function() { ... Whatever you want ... };

connection1.start();
connection2.start();

这篇关于SignalR客户具有多个连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆