def read_k_bytes(sock, remaining=0):
    """
    Read exactly `remaining` bytes from the socket.
    Blocks until the required bytes are available and
    return the data read as raw bytes. Call to this
    function blocks until required bytes are available
    in the socket.

    Arguments
    ---------
    sock  : Socket to inspect
    remaining : Number of bytes to read from socket.
    """
    ret = b""  # Return byte buffer
    while remaining > 0:
        d = sock.recv(remaining)
        ret += d
        remaining -= len(d)
    return ret