SignalR connect to multiple servers

半城伤御伤魂 提交于 2019-12-05 13:44:21

Using different $connection:

var connection1 = $.connection('/first');
connection1.start();

var connection2 = $.connection('/second');
connection2.start();

Subscribing on multiple hubs:

var connection1 = $.hubConnection("'http://server1.net/signalr");
var connection2 = $.hubConnection("http://server2.net/signalr");

var Hub1= connection1.createHubProxy('Hub1');
var Hub2= connection2.createHubProxy('Hub2');

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

Read more here: here at section Define method on client (without the generated proxy, or when adding after calling the start method)

Thank you SilentTremor. You saved me a lot of time.

If you are working with generated proxies then you can use something like:

var Hub1 = connection1.createHubProxies().<your hub class>

Replace with your own class. Then just get access to all server functions from Hub1. Example:

var Hub1 = connection1.createHubProxies().Chat;
...
Hub1.addMessage(name, message);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!