我正在开发一个带有asp net Core
后端的iOS应用。我需要在应用程序流程的某个位置创建实时连接,我在后端API上实现了SignalR
,使用官方的TS SignalR客户端没有问题。但是我无法使用纯TSClient
从中心接收消息。
connectJs() {
this.http
.post<any>('http://localhost:8083/testhub/negotiate', null)
.subscribe(x => {
const id = x.connectionId;
this.ws = new WebSocket('ws://localhost:8083/testhub?id=' + id);
this.ws.onopen = () => {
console.log('open');
};
this.ws.onerror = function(error) {
console.log(error);
};
this.ws.onmessage = data => {
console.log(data);
};
});
}
打开已打印,但是当我从后端向所有客户端发送消息时:
await _hubContext.Clients.All.SendAsync("test", "HELLO WORLD", true);
什么也没收到。