在我的应用程序中,.net核心应用程序暗含了信号R。在我的情况下,我暗示了负载均衡器,所以我有2个应用服务器。现在,当我的应用程序尝试使用基于套接字的传输与信号R建立连接时,有时会建立连接,而有些则会抛出err。
这是错误:-
An error occurred: Uncaught (in promise): Error: Unable to initialize any of the available transports.
Error: Unable to initialize any of the available transports.
启动文件
services
.AddSignalR()
.AddRedis(Configuration.GetConnectionString("ConnectionRedis"),
options => {
options.Configuration.ClientName = "MyApp";
});
app.UseSignalR(routes => {
routes.MapHub<Hub>(Configuration.GetValue<string>("SignalR:HubName"));
});
集线器连接:-
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();
}
角度UI:-
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(this.signalRHubConnection, {
accessTokenFactory: () => this.access_token,
skipNegotiation: false,
transport: signalR.HttpTransportType.WebSockets
})
.configureLogging(signalR.LogLevel.Debug)
.build();
this.hubConnection
.start()
.then(() => {
this.commonService.setGlobalVariables("conn", "test");
})
.catch();
任何人都知道为什么会这样,我两个应用服务器都使用相同的loadbalance API建立集线器连接。任何提示和想法都会有所帮助 谢谢
答案 0 :(得分:1)
您应该这样设置代码
services.AddSignalR();
app.UseSignalR(routes =>
{
routes.MapHub<ConnectionHub>("/connectionHub"); // make sure to have / here
});
像你这样的东西
private _hubConnection: HubConnection | undefined;
this._hubConnection = new HubConnectionBuilder()
.withUrl("/connectionHub")
.configureLogging(LogLevel.Error)
.build();
this._hubConnection.start().catch(err => console.error(err.toString()));
我不确定您的this.signalRHubConnection的值是什么?