def recvall(sock, num_bytes):
    """
    Receives a size-prefixed message from the send() function above.
    Thanks to Adam Rosenfield and Hedde van der Heide for the elegant solution.

    Args:
        sock: The socket to receive from.

    Returns:
        The complete message received by the socket, or None if no data is received.
    """
    received = bytes()
    while len(received) < num_bytes:
        data = sock.recv(num_bytes - len(received))
        if not data:
            return None
        received += data

    return received