【发布时间】:2021-02-01 19:30:51
【问题描述】:
我在 react-native 中使用包 @aspnet/signalr 来连接我的服务器。
在应用程序处于前台之前一切正常,如果我失去连接而不会收到错误,我可以重新连接。
当我在后台长时间打开应用程序时,我可以立即重新连接到我的服务器,但我收到错误 Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'
如何拦截这个错误?
这是我的一段代码:
connection = new signalR.HubConnectionBuilder()
.withUrl("http://192.168.xxx.xxx/notificationHub?userId=" + authInfo.userId)
.build();
connection.on("receiveMessage", data => {
console.log('*** MESSAGGIO RICEVUTO ***');
Alert.alert(data);
});
connection.start()
.then(() => console.log("Connessione avvenuta"))
.catch((err) => console.log(err);
connection.onclose()
.then(() => connection.start(););
谢谢
【问题讨论】:
标签: react-native signalr asp.net-core-signalr