Asterisk AudioSocket – “Connection reset by peer” error when streaming to Python server

What causes this “Connection reset by peer” error in AudioSocket, and how can I keep the audio stream alive for the duration of the call? Do I need to handle the AudioSocket protocol differently (e.g., handshake, audio format, or keep-alive messages) in my Python server?

It typically means the other end has closed the connection unexpectedly.