I've changed socket file flags to rb (read, bytes). Without 'bytes' script can't count length properly if we have cyrillic symbols. For example len("раз") with 'r' flags return 3, with 'rb' 6.
Some events can contain body with additional Content-Length header. DETECTED_SPEECH for example.