def send(socket, msg):
    """ Sends a message to a socket.

    Parameters
    ----------
    socket : socket
        the socket describing a connection, created by connect(url,port)
    msg : string
        the message that is to be sent
    
    Returns
    -------
    total_sent : int
        number of bytes sent; should be len(msg) or 0 if msg failed to completely send
    """
    total_sent = 0

    if socket is None or msg is None:
        return total_sent

    while total_sent < len(msg):
        sent = socket.send(msg[total_sent:].encode())
        if sent == 0:
            return 0    # message failed to completely send
        total_sent += sent

    return total_sent