Example #1
0
 def __send(self, data):
     if self.__DEBUG:
         print "Sending the following data:\n"
         print str(data)
     # encrypt the data
     encrypted = Commands.encrypt(data)
     # get the data's length
     length = Commands.pad_length(len(encrypted))
     # send the data encrypted
     self.__socket.send(length + encrypted)
Example #2
0
 def __send_to_socket(self, sock, data):
     """
     Sends the data to the given socket. First the length of the data
     (DATA_LENGTH digits), and then the data itself.
     :param sock: the socket to send the data to
     :param data: the data we want to send to the socket
     :return: if succeeded.
     """
     # encrypt the data
     encrypted = Commands.encrypt(data)
     # get the data's length
     data_len = Commands.pad_length(len(encrypted))
     # send the whole message - length and then the data itself encrypted
     sock.send(data_len + encrypted)
     # if DEBUG MODE on then print the data we sent
     if self.__DEBUG:
         address = self.__get_address_by_socket(sock)
         print >> sys.__stdout__, "Sent to <%s : %s> the following command:\n%s" % (
             address[0], address[1], data)
     # return true
     return True