---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/api/errors/31901#article
headline: "31901: Stream - WebSocket - Connection Timeout"
url: https://www.twilio.com/docs/api/errors/31901
inLanguage: en
dateModified: 2026-06-08T11:38:30.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# 31901: Stream - WebSocket - Connection Timeout

Log Type: APPLICATION

Log Level: ERROR

## Description

Twilio returns this error when the Media Stream connection request does not receive a response from your WebSocket server. Twilio uses the `url` in `<Stream>` to establish a secure `wss` connection, and your Media Streams application must allow secure WebSocket traffic on TCP port 443.

### Possible causes

* Your WebSocket server is not connected to a network or is otherwise unreachable.
* The `url` in `<Stream>` points to the wrong host or IP address. Twilio uses that `url` to open the WebSocket connection.
* An intermediate service such as ngrok, a proxy, or another routing layer is not forwarding traffic to your WebSocket server.
* A firewall or network policy is blocking secure WebSocket traffic on TCP port 443.

### Possible solutions

* Confirm that your WebSocket server is online, connected to the network, and reachable from Twilio.
* Verify that the `<Stream>` `url` is correct and uses `wss`. `wss` is the only supported protocol for Media Streams.
* If you use ngrok, a proxy, or another intermediate service, verify that it routes traffic to your WebSocket server and returns a response.
* Update your firewall rules to allow secure WebSocket connections on TCP port 443 from Twilio to your WebSocket server.
* After you restore connectivity, confirm that your server receives Twilio's initial `connected` event on the WebSocket connection.

#### Additional resources

* [Media Streams overview](/docs/voice/media-streams)
* [`<Stream>` TwiML reference](/docs/voice/twiml/stream)
* [Media Streams WebSocket messages](/docs/voice/media-streams/websocket-messages)
