# 31924: Stream - Websocket - Protocol Error

Log Type: APPLICATION

Log Level: ERROR

## Description

Twilio returns this error when your WebSocket server sends a malformed message or otherwise does not follow the WebSocket protocol during a Voice Media Stream.

### Possible causes

* The WebSocket control frame was fragmented.
* A message sent by your server did not conform to the WebSocket protocol.
* In a bidirectional Stream, your server sent a message back to Twilio that was not a supported `media`, `mark`, or `clear` message, or the message format was invalid.

### Possible solutions

* Verify the messages sent by your server.
* If you use bidirectional Media Streams with `<Connect><Stream>`, send only supported `media`, `mark`, and `clear` messages back to Twilio.
* When sending a `media` message, encode the payload as base64 `audio/x-mulaw` audio at `8000` Hz and do not include audio file header bytes.
* If you started a unidirectional Stream with `<Start><Stream>`, do not send audio or control messages back to Twilio over the WebSocket connection.

#### Additional resources

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