Skip to contentSkip to navigationSkip to topbar
Page toolsOn this pageProducts used
Looking for more inspiration?Visit the

31921: Stream - WebSocket - Close Error


ERROR: 31921

error-31921 page anchor
VOICE
ERROR

This error occurs when Twilio establishes a Media Streams WebSocket connection to your server and your server then closes that connection. In bidirectional Media Streams, closing the WebSocket from your server stops the Stream.

Possible causes

possible-causes page anchor
  • Your WebSocket server ended the connection and Twilio received a WebSocket close event.
  • Your application closed the WebSocket for a bidirectional Stream started with <Connect><Stream>. Twilio resumes the remaining TwiML only after your server closes the WebSocket connection.
  • The WebSocket connection associated with the Media Stream was closed by your server before you intended the Stream to end. Each Media Stream uses a single WebSocket connection.
  • Review your WebSocket server logs to identify the close code and the condition that caused the server to end the connection.
  • If you use bidirectional Media Streams with <Connect><Stream>, keep the WebSocket connection open for as long as you want the Stream to continue. Close it only when you intend to stop the Stream.
  • Add a statusCallback URL to <Stream> so Twilio sends stream-started, stream-stopped, and stream-error events. Use the StreamError value in that callback to capture more detail about the failure.
  • Make sure your Media Streams application accepts secure WebSocket connections from Twilio on TCP port 443.

Additional resources

additional-resources page anchor