Bonjour, voila j'essaye d'envoyer des fichiers binaires avec builder, on peut dire que je suis sur la voie mais je re�ois pas le fichier en entier du cot� du client (le serveur emet le fichier, le client recoit). Je recois de 0 a 130 Ko a chaque fois sur les 166Ko que je devrais recevoir. C'est super aleatoire. Je vous donne le code du serveur et du client :

Serveur :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
   Memo1->Lines->Add(Socket->ReceiveText()); // Le client demande d'envoyer
 
   char buffer [2048] = {0};
   FILE *input = fopen("2.jpg", "rb");
 
   if(input == NULL)
   {
        ShowMessage("Probleme d'ouverture du fichier");
        return;
   }
 
 
   while(!feof(input))
   {
        int lu = fread(buffer, 1, 2048, input);
        Socket->SendBuf(buffer, lu);
   }
   ShowMessage("Fichier envoyé");
   fclose(input);
}
Client :

Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
void __fastcall TForm1::FormActivate(TObject *Sender)
{
   ClientSocket1->Active = true ;
}
//-------------------------------------------------------------------------
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   ClientSocket1->Socket->SendText("Demande fichier");
   output = fopen("2.jpg", "wb");
   if(output == NULL)
   {
       printf("Probleme d'ouverture du fichier\n");
       return;
   }
}
//-------------------------------------------------------------------------
 
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
      TCustomWinSocket *Socket)
{
   char buffer[2048] = {0};
   int a = Socket->ReceiveBuf(buffer, 2048);
   for(int i = 0; i < a; i++) fwrite(&buffer[i], 1, 1, output);
}
//-------------------------------------------------------------------------
 
void __fastcall TForm1::ClientSocket1Error(TObject *Sender,
      TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
   Application->MessageBoxA("Une erreur est survenue" , NULL ,MB_OK ) ;
   Application->Terminate();
}
//-------------------------------------------------------------------------
 
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    ClientSocket1->Active = false;
    fclose(output);       
}
//-------------------------------------------------------------------------