gpt4 book ai didi

react-native - 如何修复 "Error: Failed to start the transport ' WebSockets : null "in reactnative using @aspnet/signalr library?

转载 作者:行者123 更新时间:2023-12-03 07:47:10 25 4
gpt4 key购买 nike

连接到服务器时,我不断收到无法启动传输“WebSockets”:null 的消息。

我正在reactnative移动应用程序中实现一个简单的聊天。我正在使用 @aspnet/signalr(version-1.1.4) 库。我收到此错误 - 错误:无法启动传输“WebSockets”:null。 在此处查看日志 Im getting following logs in chrome

componentDidMount(){

try {

const connection = new signalR.HubConnectionBuilder() //Connect to a hub
.withUrl(baseUrl + `/chatbus`, {
transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.LongPolling,
'content-type': 'application/json',
accessTokenFactory: () => authToken //for authorization
})
.configureLogging(signalR.LogLevel.Debug)
.build();

connection.on('NotifySignalR', (ChatObject) => {
console.log(ChatObject);

});

connection.start()
.then(() => {
console.log('Chat Connection started.');
console.log('Now connected, connection ID=' + connection.id);
this.initalAttemptForChat = true;
connection.invoke("start");
})
.catch(() => {
this.initalAttemptForChat = false;
console.log('Error while establishing chatbus connection!');
});

} catch (e) {
console.log("error ", e);
throw e;
}
}

最佳答案

如果您的应用程序位于 Windows Server 中,只需启用“WebSocket 协议(protocol)”即可。

“添加或删除程序”>“打开或关闭 Windows 功能”>“Web 服务器 (IIS)”>“Web 服务器”>“应用程序开发”>“WebSocket 协议(protocol)”。

关于react-native - 如何修复 "Error: Failed to start the transport ' WebSockets : null "in reactnative using @aspnet/signalr library?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56423954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com