In role IO::Socket§

See primary documentation in context for method recv.

method recv(IO::Socket:D: Cool $elems = Inf, :$bin)

Receive a packet and return it, either as a Blob if :bin was passed, or a Str if not. Receives up to $elems or 65535 (whichever is smaller) bytes or characters.

If the socket has previously been read from in non-:bin mode, it's not always safe to read from it in :bin mode again. Depending on the decoder it's possible for the :bin read to skip over bytes that the decoder has read ahead messing up the order of bytes and chars. This effect can occur with the UTF-8 decoder and if the previously decoded char could still receive combiners.

In Rakudo versions prior to 2024.07 mixing of binary and non-binary reads is unsupported.

Fails if the socket is not connected.