Send data by packet on socket

def send_by_packet(self, data):
        """
        Send data by packet on socket
        """
        total_sent = 0
        while total_sent < PACKET_SIZE:
            sent = self.sock.send(data[total_sent:])
            if sent == 0:
                raise RuntimeError("socket connection broken")
            total_sent += sent
        return total_sent