Reputation: 2464
In my application I had implemented signal R with .net core application. in my case I had implemented load balancer, so I have 2 app server. Now when my application try to make connection with signal R, using socket based transport, sometimes connection established and some it's throw err.
Here is error:-
An error occurred: Uncaught (in promise): Error: Unable to initialize any of the available transports.
Error: Unable to initialize any of the available transports.
Start up file
services
.AddSignalR()
.AddRedis(Configuration.GetConnectionString("ConnectionRedis"),
options => {
options.Configuration.ClientName = "MyApp";
});
app.UseSignalR(routes => {
routes.MapHub<Hub>(Configuration.GetValue<string>("SignalR:HubName"));
});
Hub connection:-
public override Task OnConnectedAsync()
{
return base.OnConnectedAsync();
}
Angular 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();
Any one have idea why this happed, my both app server using same loadbalance api to make a hub connection. any hint and idea would be helpfull thank you
Upvotes: 1
Views: 365
Reputation: 20092
You should set up your code like this
services.AddSignalR();
app.UseSignalR(routes =>
{
routes.MapHub<ConnectionHub>("/connectionHub"); // make sure to have / here
});
In your angular some thing like
private _hubConnection: HubConnection | undefined;
this._hubConnection = new HubConnectionBuilder()
.withUrl("/connectionHub")
.configureLogging(LogLevel.Error)
.build();
this._hubConnection.start().catch(err => console.error(err.toString()));
I'm not sure about your this.signalRHubConnection what is the value of that ?
Upvotes: 2