Error: Failed to start the connection: Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
WebSocketTransport.js:49 WebSocket connection to 'ws://xxxxxx/production/web-services/hubs/spreadhub' failed:
Angular.ts
ngOnInit(): void {
// For signalR Hub connection
this.connection = new HubConnectionBuilder()
.withUrl('http://xxx.xxx.com/production/web-services/hubs/spreadhub', { // localhost from **AspNetCore3.1 service**
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.build();
this.connection.on('dataReceived', (data: string) => {
var model = JSON.parse(data);
});
this.connection.start().then(() => { // to start the server
console.log('server connected!!!');
}).catch(err => console.log(err));
}
You don't need to specify the full url, just the hub you want to connect to... Assuming your hub name is spreadhub you just need:
this.connection = new HubConnectionBuilder()
.withUrl('https://localhost:5001/spreadhub', { // localhost from **AspNetCore3.1 service**
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.build();
On the server, if deployed to azure, don't forget to turn on websockets like: