[英]signalr - with different clients
我正在嘗試設置signalR系統。
我使用兩個瀏覽器和同一個集線器來工作示例代碼。 消息已發送和接收。
現在,當我創建另一個頁面並嘗試將消息發送到集線器時,它似乎可以正常工作,這意味着它不會崩潰,但是沒有任何內容傳輸給其他客戶端。
我以為我正在從所有客戶端訪問同一個消息中心,但是也許我錯過了一些東西。
是否可以將不同的網站連接到同一消息中心?
開始編輯
根據要求...。這是我在第二個客戶端上使用的代碼...
var connection = $.hubConnection('http://xxxxxxxxx.azurewebsites.net/');
var contosoChatHubProxy = connection.createHubProxy('MessagePump');
// contosoChatHubProxy.on('Send', function (name, message) {console.log(name + ' ' + message);});
$.connection.hub.start()
.done(function () {
console.log('Now connected, connection ID=' + $.connection.hub.id); // returns an ID
// $.connection.hub.send('testing', 'this is a test from the client');
// contosoChatHubProxy.send("testing");
// contosoChatHubProxy.invoke('testing', 'this is a test for the client 1');
// contosoChatHubProxy.invoke('say', 'this is a test for the client 2');
// contosoChatHubProxy.invoke('Send', 'This is a test for client 3');
// $.connection.hub.send('testing', 'this is a test from the client 4');
contosoChatHubProxy.invoke('messagePump', 'user', 'this is a test message for 5');
})
.fail(function(){ console.log('Could not Connect!'); });
這就是我在螢火蟲中看到的
從我能做的代碼來看,代理似乎正在本地加載,甚至看不到遠程系統集線器...
僅連接到遠程系統集線器的控制台應用程序能夠發送和接收消息。
順便說一句-我嘗試了大寫可以小寫(MessagePump,messagePump),但它沒有改變結果。
var connection = $.hubConnection('http://xxxxxxxxx.azurewebsites.net/');
您正在嘗試連接其他網站。 此http://xxxxxxxxx.azurewebsites.net/
應該允許跨域請求。否則,您將無法連接。 如果您可以管理http://xxxxxxxxx.azurewebsites.net/
,則應將信號器配置為:
public class Startup { public void Configuration(IAppBuilder app) { // Branch the pipeline here for requests that start with "/signalr" app.Map("/signalr", map => { // Setup the CORS middleware to run before SignalR. // By default this will allow all origins. You can // configure the set of origins and/or http verbs by // providing a cors options with a different policy. map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration { // You can enable JSONP by uncommenting line below. // JSONP requests are insecure but some older browsers (and some // versions of IE) require JSONP to work cross domain // EnableJSONP = true }; // Run the SignalR pipeline. We're not using MapSignalR // since this branch already runs under the "/signalr" // path. map.RunSignalR(hubConfiguration); }); } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.