Ujjwal Manandhar
Ujjwal Manandhar

Reputation: 276

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

Upvotes: 10

Views: 22493

Answers (2)

InvAdrian
InvAdrian

Reputation: 33

For anyone using Windows Server 2012, the steps are as follows (https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support):

To enable support for the WebSocket Protocol on Windows Server 2012, use the following steps:

  1. Open Server Manager.
  2. Under the Manage menu, click Add Roles and Features.
  3. Select Role-based or Feature-based Installation, and then click Next.
  4. Select the appropriate server, (your local server is selected by default), and then click Next.
  5. Expand Web Server (IIS) in the Roles tree, then expand Web Server, and then expand Application Development.
  6. Select WebSocket Protocol, and then click Next.
  7. If no additional features are needed, click Next.
  8. Click Install.
  9. When the installation completes, click Close to exit the wizard.

Upvotes: 0

Ciro Hidalgo
Ciro Hidalgo

Reputation: 121

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".

Upvotes: 9

Related Questions