def send(sock, msg):
    """
    Send message over the socket.
    """
    num_sent = 0
    while num_sent < len(msg):
        sent = sock.send(msg[num_sent:])
        if not sent:
            raise RuntimeError('socket connection broken')
        num_sent = num_sent + sent
    return num_sent
