尝试创建简单的angular/signalR应用程序。
我的Hub类:
namespace Gameserver.Hubs
{
public class SignalRHub : Hub
{
public Task Send()
{
return Clients.All.InvokeAsync("Send", "Message from the server");
}
}
}我的startup.cs:
public partial class Startup
{
public void Configure(IAppBuilder app)
{
app.MapSignalR();
}
}和一个组件:
import { Component, OnInit } from '@angular/core';
import { HubConnection } from '@aspnet/signalr-client';
export class CoreComponent implements OnInit
{
private connection: HubConnection;
ngOnInit(){
this.connection = new HubConnection('http://localhost:49756/signalr/');
this.connection.on('send', data =>{
console.log(data);
})
this.connection.start()
.then(() => console.log('connected'))
.catch(err => console.log('Error while establishing connection: ' + err));
}运行后,从Loggers.js获得此错误
Error: Failed to start the connection. SyntaxError: Unexpected end of JSON input有人能帮我纠正这个错误吗?
发布于 2018-02-22 14:06:06
在尝试了另外两个包之后,我发现其中一个运行良好。https://github.com/HNeukermans/ng2-signalR https://www.npmjs.com/package/ng2-signalr
https://stackoverflow.com/questions/48907590
复制相似问题