Signalr 2应该在Windows 10,kestrel和aspnet core 1.0上使用websockts

时间:2016-08-20 19:16:05

标签: signalr

在启动时使用以下内容

        app.UseWebSockets();

        app.Map("/signalr", signalrApp =>
        {
            signalrApp.UseKatana(config =>
            {
                config.RunSignalR(new HubConfiguration
                {
                    EnableDetailedErrors = true,

                });
            });
        });

和一个简单的中心

public class MyHubBroadcaster : Hub
{
     public void Test()
    {
        Clients.All.addContosoChatMessageToPage("a", "b");
    }
}

并启动信号器

var connection = $.hubConnection();
connection.logging = true;
var contosoChatHubProxy = connection.createHubProxy('myHubBroadcaster');
contosoChatHubProxy.on('addContosoChatMessageToPage', function (userName, message) {
    console.log(userName + ' ' + message);
});
console.log(connection);
var promise = connection.start();
promise.done(function () {
    console.log('Now connected, connection ID=' + connection.id);
    setInterval(() => {
        contosoChatHubProxy.invoke('test').done((d) => console.log(d));
    }, 10000);
})
promise.fail(function () { console.log('Could not connect'); });

negotiantion返回TryWebSockets = false

我错过了什么或应该这样做吗?

main.cs

            var host = new WebHostBuilder()
               .UseKestrel()
               .UseContentRoot(Directory.GetCurrentDirectory())
               .UseIISIntegration()
               .UseStartup<Startup>()
               .Build();

            host.Run();

project.json

{
  "dependencies": {
    "Microsoft.AspNet.SignalR.Core": "2.2.1",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.ServiceFabric": "5.1.163",
    "Microsoft.ServiceFabric.Data": "2.1.163",
    "Microsoft.ServiceFabric.Services": "2.1.163",
    "S-Innovations.ServiceFabric.Gateway.RegistrationMiddleware.AspNetCore": "1.0.1-pre-2016082001",
    "Microsoft.AspNetCore.Owin": "1.0.0",
    "AspNet.Hosting.Katana.Extensions": "1.0.0-alpha3-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.WebSockets.Server": "0.1.0"
  },

  "tools": {
  },

  "frameworks": {
    "net452": {
      "frameworkAssemblies": {
        "System.Numerics": "4.0.0.0"
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
  }
}

0 个答案:

没有答案