data is not recieve by python server

  python, qt, server, sockets

im making a backup program, i send all the data using tcp sockets in C++, but even when my logs said the data its send, its not recive on my python side, honestly i dont know what im missing i was recieving the data and making the file a few days ago, can anyone take a look at it?

The idea is to send the File and the file data, then the server recieve it and creates a folder with the datetime and creates the file inside, it can be 1 file or 1000 files

C++ client, it send the data

void Server::Tcp_Send(QString File_Data){
   Gen L;
   QString Ip("192.168.1.68");
   QString filename, data_info, size, size_8_Byte;
   qint64 filesize;
   quint64 x = 0;
  
   bool yes = false;
   QByteArray block, block_file;
   filename.append("Data/" + File_Data);
   QFile Archivo(filename);
  
   if (Tcp_socket->state() == QAbstractSocket::UnconnectedState){
      L.log("Before conecction");
      Tcp_socket->connectToHost(Ip, 7000, QIODevice::WriteOnly);
      Tcp_socket->waitForConnected();
      QDataStream salida(Tcp_socket);

      Archivo.open(QIODevice::ReadOnly);
      block_file = Archivo.readAll();
      block.append(block_file);
      filesize = Archivo.size();
      Archivo.close();
      data_info = File_Data + "<SEPARATOR>" + QString::number(filesize) + "<SEPARATOR>";
      block.prepend(data_info.toUtf8());

      size = QString::number(block.size());
      size_8_byte = size.rightJustified(8, ' ');
      block.prepend(size_8_byte.toUtf8());
      if (Tcp_socket->isValid()){       
          L.log("before sending data");
          salida.writeRawData( (char*)(block.data()), block.size() );
          yes = Tcp_socket->flush();
          Tcp_socket->waitForBytesWritten();
          L.log(block.data());
      if (yes == true) {L.log("Data Send");}  else  {L.log("The Data was not send"); }
       L.log ("Coneection terminated");
       }
   }  
 }

python side, this is the server side

def servidor():   # handler principal
    print (f"Iniciando el Servidor Sockets")
    print (f"Current IP Addres: " + get_ip())
    log("Iniciando servidor")
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind((get_ip(), 8000))   # set server ip and port
    server.listen(2)  # number of connectios allowed
    conn, address = server.accept() # Accept the Client connection
        # add the separator <SEPARATOR> to diferentiate betwenn files
        # send filename first, then size and the file itself last
    upack = struct.Struct('8s')   # codificacion erase all the 8s's
    msg = b''     # same as above, erase all the b's

    while True:
    #while not msg == '<FINAL>':
        # data_info = conn.recv()
        # log(data_info)
        
        while True:
            #1024 is the bandwidth bits 
            try:
                while len(msg) < 8:
                    try:
                        msg += conn.recv(100) 
                    except:
                        break
                sice = upack.unpack(msg[:8])[0]
                sice = int(sice.decode("utf-8").strip())  # decodificacion en utf-8
                msg = msg[8:]
                #while not msg == '<FINAL>':
                while (msg):   # creacion y escritura del archivo
                    try:
                        msg += conn.recv(1024)  # 1024
                        
                    except:
                        break
                log(msg)
                filename, filesize, file_Data = msg.split("<SEPARATOR>")   # split the name and size of file and file data itself
                filename, no_use = filename.split(".")  # the extension its been send i need to fix that later
                file_name = crear_directorio() + filename + '.db'
                print (file_name)
                file = open(file_name, 'wb')  # open file for writing in binary
                file.write(file_Data)
                file.close()
                log("archivo " + filename + ".db creado")
                #log(file_Data)
            except:
                print (f"coneccion terminada")
                log("Conneccion Terminada por el cliente")

Source: Python Questions

LEAVE A COMMENT