Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 信号器-具有不同的客户端_Javascript_Signalr - Fatal编程技术网

Javascript 信号器-具有不同的客户端

Javascript 信号器-具有不同的客户端,javascript,signalr,Javascript,Signalr,我正试图设置一个信号系统 我使用两个浏览器和同一个集线器使示例代码正常工作。发送和接收消息 现在,当我创建了一个不同的页面,并尝试向中心发送消息时,它似乎可以正常工作,这意味着它不会爆炸,但不会向其他客户端传输任何信息 我以为我从所有客户机访问同一个消息中心,但也许我遗漏了什么 是否可以将不同的网站连接到同一个消息中心 开始编辑 应要求。。。。这是我在第二个客户端上使用的代码 var connection = $.hubConnection('http://xxxxxxxxx.azurewe

我正试图设置一个信号系统

我使用两个浏览器和同一个集线器使示例代码正常工作。发送和接收消息

现在,当我创建了一个不同的页面,并尝试向中心发送消息时,它似乎可以正常工作,这意味着它不会爆炸,但不会向其他客户端传输任何信息

我以为我从所有客户机访问同一个消息中心,但也许我遗漏了什么

是否可以将不同的网站连接到同一个消息中心

开始编辑

应要求。。。。这是我在第二个客户端上使用的代码

  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!'); });
这就是我在firebug中看到的

从我对代码的理解来看,代理似乎正在本地加载,甚至没有看到远程系统集线器

仅连接到远程系统集线器的我的控制台应用程序能够发送和接收消息

顺便说一句-我试过上can下外壳(MessagePump,MessagePump) 但这并没有改变结果

 var connection = $.hubConnection('http://xxxxxxxxx.azurewebsites.net/');
您正在尝试连接其他网站。这个
http://xxxxxxxxx.azurewebsites.net/
应允许跨域请求。否则您无法连接。如果您可以管理
http://xxxxxxxxx.azurewebsites.net/
,您应该像这样配置信号器:

您正在尝试连接其他网站。这个
http://xxxxxxxxx.azurewebsites.net/
应允许跨域请求。否则您无法连接。如果您可以管理
http://xxxxxxxxx.azurewebsites.net/
,您应该像这样配置信号器:


为了获得帮助,您应该添加相关代码是的,您需要展示您的工作,否则很难说问题出在哪里:-)我猜您需要覆盖Hub实例的OnConnected方法,以便将连接的客户端放入适当的组中,然后确保将消息发送到正确的组。您的用例非常正常。您应该添加相关代码以获得帮助。是的,您需要展示您的工作,否则很难说问题是什么:-)我猜您需要覆盖Hub实例的OnConnected方法,以便将连接的客户端放入适当的组中,然后确保将消息发送到正确的组。您的用例非常正常。
   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);
            });
        }
    }