您好,我尝试将 signalR 与 asp.net mvc 5 和 Angular 7 一起使用,但无法在集线器之间建立连接
这是我的代码
角7
import { Component, OnInit } from '@angular/core';
import { HubConnection, HubConnectionBuilder } from '@aspnet/signalr';
import * as $ from '@aspnet/signalr'
@Component({
selector: 'app-admin-dashboard',
templateUrl: './admin-dashboard.component.html',
styleUrls: ['./admin-dashboard.component.scss']
})
export class AdminDashboardComponent implements OnInit {
private _hubConnection: HubConnection;
constructor() {
this._hubConnection = new HubConnectionBuilder()
.withUrl("http://localhost:4200/hub/cashnet", {
skipNegotiation: true,
transport: $.HttpTransportType.WebSockets
})
.configureLogging($.LogLevel.Information)
.build();
this._hubConnection.start().then(() => {
console.log('Hub connection started');
}).catch(err => {
console.log('Error while establishing connection :(')
});
this._hubConnection.on('sendMessage', …Run Code Online (Sandbox Code Playgroud)