# 31902: Stream - WebSocket - Connection Refused

Log Type: APPLICATION

Log Level: ERROR

## Description

Twilio returns this error when a Media Stream cannot establish a WebSocket connection because the destination host refuses the connection request. Media Streams use the `<Stream>` noun and connect to your endpoint over `wss`.

### Possible causes

* The `url` in `<Start><Stream>` or `<Connect><Stream>`, or the `Url` used with the Stream resource, points to the wrong host, path, or port.
* Your WebSocket server is down, not listening, or otherwise unavailable when Twilio tries to connect.
* Your network or firewall is blocking secure WebSocket traffic to your server. Media Streams require secure WebSocket connections on TCP port 443 from Twilio to your WebSocket server.
* The endpoint is not accepting a secure `wss` connection. Twilio supports `wss` for Media Streams.

### Possible solutions

* Verify that the Media Stream destination is the correct `wss` endpoint and that the host, path, and port are correct in your `<Stream>` `url` or Stream resource `Url`.
* Confirm that your WebSocket server process is running and able to accept incoming connections when the call starts the stream.
* Update your firewall or network rules to allow secure WebSocket connections on TCP port 443 from Twilio to your WebSocket server.
* If the refusal was caused by a temporary service interruption, retry the connection after your WebSocket service is healthy again.

#### Additional resources

* [Media Streams Overview](/docs/voice/media-streams)
* [TwiML Voice: `<Stream>`](/docs/voice/twiml/stream)
* [Media Streams Configuration](/docs/global-infrastructure/firewall-configurations/media-streams-configuration)
