• Miércoles 24 de Abril de 2024, 04:22

Autor Tema:  Problema Mandar Archivo De Servidor A Cliente  (Leído 877 veces)

pameXXX

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Problema Mandar Archivo De Servidor A Cliente
« en: Viernes 20 de Julio de 2007, 16:12 »
0
Hola,

Estoy haciendo una aplicacion cliente servidor y tengo un problema. Para mandar archivos
del servidor al cliente utilizo el siguiente codigo:

parte servidor:


   CFile myFile;
   myFile.Open("prueba.html", CFile::modeRead | CFile::typeBinary);

   int myFileLength = myFile.GetLength(); // Going to send the correct File Size

   m_sConnectSocket.Send(&myFileLength, 4); // 4 bytes long

   byte* data = new byte[myFileLength];

   myFile.Read(data, myFileLength);

   m_sConnectSocket.Send(data, myFileLength); //Send the whole thing now

   myFile.Close();
   delete data;


parte cliente:


   CFile file;
      
   int dataLength;
   m_sConnectSocket.Receive(&dataLength, 4); //Now we get the File Size first

   file.Open("C:\\prueba.html",CFile::modeWrite |CFile::modeCreate| CFile::typeBinary);
   byte* data=new byte[dataLength];

   m_sConnectSocket.Receive(data,dataLength);

   file.Write(data, dataLength);

   file.Close();

la variable m_sConnectSocket es tipo CAsyncSocket. El problema q tengo es q a veces anda y a veces llega mal el archivo.
A veces llega perfecto, a veces mas corto y a veces mas corto y con caracteres extranios...

POR FAVOR SI ALGUIEN PUEDE AYUDARME PORQ LA VERDAD NO PUEDO ENCONTRAR EL ERROR....

GRACIAS DE ANTEMANO,

PAMELA