Ejemplo n.º 1
0
def send_message(msg):
    message = msg.encode(FORMAT) # Encodes the message itself

    # -----MESSAGE ENCRYPTION----
    message = En.ENCRYPT(key, message)
    # ---------------------------

    # [ATTENTION] When obtaining "message_length", the "message" must be the one you will sent!!
    message_length = str(len(message)) # Converts the length of the encoded and encrypted message to a string

    send_length = message_length.encode(FORMAT) # Formats the length of the encoded and encrypted message
    send_length += b" " * (HEADER - len(send_length)) # Padds the message

    print("\n", msg)
    print(message_length, type(message_length))
    print(send_length, type(send_length))
    print(message, "\n")



    # return message

    conn.send(send_length)
    conn.send(message)