Here is some actual code written in PureBasic. It is executed in a loop.
It works. The first packet plays OK, then the browser stops accepting data.
Procedure AudioLoop()
Pa_ReadStream(*my_stream, *writeBuffer, framesPerBuffer)
CreateFile(10, "temp.raw"):
WriteData(10, *writeBuffer, framesPerBuffer*bytesPerFrame): CloseFile(10)
RunProgram("\Programs\Opus\opusenc.exe" , "--max-delay 0 --quiet --comp 0 --raw-rate 44100 --raw-chan 1 temp.raw temp.opus", "./", #PB_Program_Wait)
header$="HTTP/1.1 200 OK"+#CRLF$
header$+"Server: 127.0.0.1:8000" + #CRLF$
header$+"Content-Type: audio/ogg"+#CRLF$
header$+"Cache-Control: no-cache"+#CRLF$
header$ +#CRLF$
ReadFile(10, "temp.opus"): ReadData(10, *writeBuffer+Len(header$), leng): : CloseFile(10)
If ClientID <> 0
SendNetworkString(ClientID, header$)
result = SendNetworkData(ClientID, *tempBuffer, leng)
EndIf
EndProcedure
If I join the header and the data and send them together, the result is the same.