【问题标题】:How to fix " Error: Failed to start the transport 'WebSockets': null " in reactnative using @aspnet/signalr library?如何使用 @aspnet/signalr 库在 reactnative 中修复“错误:无法启动传输 'WebSockets': null ”?
【发布时间】:2019-10-18 19:22:53
【问题描述】:

连接到服务器时,我不断收到 Failed to start the transport 'WebSockets': null 。

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

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;
    }
}

【问题讨论】:

    标签: react-native signalr


    【解决方案1】:

    如果您在 Windows Server 中有应用,只需启用“WebSocket 协议”即可。

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

    【讨论】:

    • 我在哪里可以做到这一点?
    • 这对我很有帮助,非常感谢!
    • Linux Ubuntu 18 服务器怎么样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    • 2016-10-16
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多