Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix " Error: Failed to start the transport 'WebSockets': null " in reactnative using @aspnet/signalr library?

I keep getting Failed to start the transport 'WebSockets': null when connecting to server.

I'm implementing a simple chat in reactnative mobile app. And I'm using @aspnet/signalr(version-1.1.4) library. I am getting this error - Error: Failed to start the transport 'WebSockets': null. See logs here 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;
    }
}
like image 982
Ujjwal Manandhar Avatar asked Jun 03 '19 08:06

Ujjwal Manandhar


1 Answers

If you have you app in Windows Server just enable thw "WebSocket Protocol".

"Add or Remove Programs">"Turn Windows features on or off" > "Web Server(IIS)">"Web Server">"Application Development">"WebSocket Protocol".

like image 139
Ciro Hidalgo Avatar answered Oct 22 '22 08:10

Ciro Hidalgo