IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Envoyer un fichier par TCP/IP


Sujet :

C++Builder

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 7
    Par défaut Envoyer un fichier par TCP/IP
    Resalut!! Cette fois, mon souci viendrai d'envoyer non pas des données mais des fichier par TCP. Je veux que le client envoie un fichier, .txt simplement au serveur. J'ai déjà trouver plusieurs exemple mais je pense pas que cela soit aussi compliké. En plus, j'utilise Builder C++ donc les fonction sont pour la pluspart déjà codé donc suffit de trouver la bonne... facile à dire...

  2. #2
    Membre chevronné
    Avatar de Altau
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    296
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 296
    Par défaut
    Je ne connais pas de composant qui fasse cela. Si tu ne parviens pas à en trouver et que tu ne veux pas écrire toi-même le code de cette fonction, tu peux avantageusement utiliser des protocoles standards comme HTTP ou FTP pour arriver à tes fins.

  3. #3
    Membre expérimenté Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par défaut
    il existe bien une fonction ! cherche dans sendfile

    methode du socket ou tcp

    j'en ia crée une qui lit le contenu du fichier et qui l'envoi paquet par paquet :
    problem lent parfois perte !

    j'ai fait une envoi via stream ca marche nikel , pas tester avec les fichier mais en envoyant des images screenshot d'un pc qui se trouvait en reseau

    voici un exemple : tu dois utilise le socket tcp

    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
     
    partie envoie :
     
    void TForm1::Camera()
    {
     
    try
    {
     tcp->Connect();
     Sleep(timer=500);
     sendstr();
    }
     catch(...){}
     
    }
    //-------------------------------------------------------------------------
    void TForm1::sendstr()
    {
     TMemoryStream *stream = new TMemoryStream();
     TJPEGImage *jpg = new TJPEGImage();
     Graphics :: TBitmap *bmp = new Graphics :: TBitmap();
     TRect *rect = new TRect();
     TPicture *img = new TPicture();
     
     img->Bitmap->Height = Screen->Height;
     img->Bitmap->Width = Screen->Width;
     
     int scrw = Screen->Width, scrh = Screen->Height;
     
     HWND hwnd = GetDesktopWindow();
     HDC hDC = GetDC(hwnd);
     
     BitBlt(img->Bitmap->Canvas->Handle,0,0,scrw,scrh,hDC,0,0,SRCCOPY);
     
    try
    {
     jpg->Assign(img->Bitmap);
     jpg->CompressionQuality = 15;
     bmp->Width = jpg->Width -50;
     bmp->Height = jpg->Height -50;
     rect->Left = 0;
     rect->Top = 0;
     rect->Right = bmp->Width-1;
     rect->Bottom = bmp->Height-1;
     bmp->Canvas->StretchDraw(*rect,jpg);
     jpg->Assign(bmp);
     jpg->SaveToStream(stream);
     jpg->Free();
     bmp->Free();
    }
    catch (...){}
     
    try
    {
     Form1->tcp->OpenWriteBuffer();
     Form1->tcp->WriteStream(stream);
     Form1->tcp->CloseWriteBuffer();
     stream->Free();
     Form1->tcp->Disconnect();
    }
    catch(...){}
     
    }
    //-------------------------------------------------------------------------
     
    partie reception:
     
    void __fastcall TForm8::tcpExecute(TIdPeerThread *AThread)
    {
    TMemoryStream *stream = new TMemoryStream();
    TJPEGImage *jpg = new TJPEGImage();
     
    AThread->Connection->ReadStream(stream, -1, true);
    stream->Position =0;
    jpg->LoadFromStream(stream);
    Form5->espion->Picture->Graphic = jpg;
     
    stream->Free();
    jpg->Free();
    }
    //--------------------------------------------------------------
    programme complet qui lit un fichier et qu'il l'envoie
    utilisation socket
    il ya les 3 fichier
    cpp = le code
    .h = les declarations
    dmf = l'interface

    cree un programe avec une form , ferme le programme et remplace leur contenue par ces 3 fichiers

    ps : il ya des ligne qui ne servent a rien , cela me servait pour debugger !
    elle est tres vielle cette source !
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
     
    //---------------------------------------------------------------------------
    UNIT1.cpp
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
        SIZE = 4096;
     
        AfficheLocalIP();
     
        TRegistry *reg = new TRegistry();
     
        reg->RootKey = HKEY_CURRENT_USER; //HKCU \Software \Microsoft \Windows \CurrentVersion \Policies \Explorer
        reg->OpenKey("\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",true);
     
        try{
              Edit1->Text = reg->ReadString("Desktop");    // bureau
              Edit1->Text = Edit1->Text + "\\"; 
              Edit2->Text = Edit1->Text;
              bureau = Edit1->Text;
           }
           catch(...){}
        reg->CloseKey();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      Pub->Picture = NULL;
       OpenDialog1->Execute();
     
       Edit1->Text = OpenDialog1->FileName;
     
       if(Edit1->Text.IsEmpty()) return;
     
       AnsiString Dest;
       Dest =  ExtractFilePath(Edit2->Text.c_str()) + ExtractFileName(Edit1->Text.c_str());
       Edit2->Text = Dest;
     
             // On crée le buffer et on ouvre le fichier en binaire
    	FILE *FichierEnvoi = fopen(Edit1->Text.c_str(), "rb");
     
            // Crée le fichier en mode binaire
            FILE *FichierRecu = fopen(Edit2->Text.c_str(), "wb");
     
    	// On envoi le fichier tant qu'on est pas a la fin
    	while(!feof(FichierEnvoi))
    	{
    	  memset(buf2, 0, SIZE);
     
    	  fread(buf2, 1, SIZE, FichierEnvoi); // lecture
     
                   fwrite(buf2, 1, SIZE, FichierRecu); // ecriture binaire pour l'envoie
     
            }
            fclose(FichierEnvoi); fclose(FichierRecu);
            try
            {Pub->Picture->LoadFromFile(Edit2->Text);}
            catch(...){};
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ConnexionClick(TObject *Sender)
    {
      if( Form1->Client->Active == false )
        { Form1->Client->Address = Form1->IpServeur->Text;
          Form1->Client->Open();   // renvoi true ou false
        }        
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ClientConnect(TObject *Sender,
          TCustomWinSocket *Socket)
    {
    Edit4->Text = " Connexion reussi ";
    Connexion->Enabled=false;
    Edit3->Text = Socket->RemoteAddress;
    Edit5->Text = Socket->RemoteHost;
    Edit6->Text = Socket->RemotePort;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ClientDisconnect(TObject *Sender,
          TCustomWinSocket *Socket)
    {
    Edit4->Text = " Serveur Deconnecté ";
    Connexion->Enabled=true;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ClientError(TObject *Sender,
          TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
    {
    ErrorCode = 0;
    Edit4->Text = " Connexion echoué ";
    Connexion->Enabled=true;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ServerClientConnect(TObject *Sender,
          TCustomWinSocket *Socket)
    {
    Edit3->Text = Socket->RemoteAddress;
    Edit5->Text = Socket->RemoteHost;
    Edit6->Text = Socket->RemotePort;
    Edit4->Text = " Connexion Reussi ";
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ServerClientError(TObject *Sender,
          TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
    {
    ErrorCode = 0;
    Edit4->Text = " Serveur Deconnecté ";
    Connexion->Enabled=true;       
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FCTTimer(TObject *Sender)
    {
      static int temp=0;
     
    	// On envoi le fichier tant qu'on est pas a la fin
    	if(!feof(FichierEnvoi))
    	{
               info_send->Caption = "Envoi en cours....";
     
               memset(buf2, 0, SIZE);
     
               fread(buf2, 1, SIZE, FichierEnvoi);
     
               sec = (sec + FCT->Interval);
     
               if(sec==1000) { sec=0; min++; }
     
               if(min==60) { her++; min=0; }
     
               timer->Caption =  AnsiString(her) + ":" + AnsiString(min);// + ":" + AnsiString(sec);
     
               Client->Socket->SendBuf(buf2,SIZE);
     
            }
            else
            { FCT->Enabled = false;
              temp = 0; sec=min=her=0;
              fclose(FichierEnvoi);
              Client->Socket->SendBuf("End_File",10);
              info_send->Caption = "Envoi Terminé";
            }
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button3Click(TObject *Sender)
    {
            error->Visible = false;
     
           // On crée le buffer et on ouvre le fichier en binaire
            FichierEnvoi = fopen(Edit1->Text.c_str(), "rb");
     
            if(FichierEnvoi==NULL) return;
     
            try
            {Pub->Picture->LoadFromFile(Edit1->Text);}
            catch(...){};
     
            AnsiString name;
            name = ExtractFileName(Edit1->Text.c_str());
            name = "_" + name + "-Start_File";
     
            Client->Socket->SendBuf(name.c_str(),50);
     
            timer->Caption =  "00:00:00";
     
            FCT->Enabled = true;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::ServerClientRead(TObject *Sender,
          TCustomWinSocket *Socket)
    {
         memset(buf, 0, SIZE);
         Socket->ReceiveBuf(buf,SIZE);  // message envoyé par un client distant
     
       if( strstr(buf,"Start_File")!=NULL )
          { info_send->Caption = "Envoi en cours....";
            char *ptr; ptr = strtok(buf,"-");
            Edit2->Text = bureau;
            Edit2->Text = Edit2->Text + AnsiString(ptr);
           	FichierRecu = fopen(Edit2->Text.c_str(), "w");
            fclose(FichierRecu);
            FichierRecu = fopen(Edit2->Text.c_str(), "ab");
            Pub->Picture = NULL;
            return;
          }
     
        if( strcmp(buf,"End_File")!=0 )
        {
           sec = (sec + FCT->Interval);
     
          if(sec==1000) { sec=0; min++; }
            if(min==60) { her++; min=0; }
     
          timer->Caption =  AnsiString(her) + ":" + AnsiString(min);// + ":" + AnsiString(sec);
     
          if(FichierRecu!=NULL)
            fwrite(buf, 1, SIZE,FichierRecu);
           else
           error->Visible = true;
        }
        else
         { fclose(FichierRecu);
           info_send->Caption = "Envoi Terminé";
           sec=min=her=0;
           Pub->Picture = NULL;
           try
           {Pub->Picture->LoadFromFile(Edit2->Text);}
            catch(...){};
     
         }
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::RadioButton1Click(TObject *Sender)
    {
    Connexion->Enabled = false;
    Server->Active = true;
    AfficheLocalIP();
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::RadioButton2Click(TObject *Sender)
    {
    Connexion->Enabled = true;
    Server->Active = false;
    IpServeur->Text = "000.000.000.000";
    }
    //---------------------------------------------------------------------------
     void TForm1::AfficheLocalIP()
    {
      struct sockaddr_in sin ;
      struct hostent * phe ;
      char FAR buffer[64] ;
     
      WORD wVersionRequested;
      WSADATA wsaData;
      int err;
     
      wVersionRequested = MAKEWORD(1, 1);
      err = WSAStartup(wVersionRequested, &wsaData);
     
        if (err != 0)
        {
           Edit1->Text = "Impossible de trouver winsock.dll";
        }
        gethostname(buffer, sizeof(buffer)) ;
        phe = gethostbyname(buffer) ;
     
        if(phe==NULL)
        {
         // exit(1) ;
        }
     
      memcpy(&sin.sin_addr.s_addr, phe->h_addr, phe->h_length);
     
      IpServeur->Text  =  AnsiString(inet_ntoa(sin.sin_addr));
     
      WSACleanup() ;
    }
    //--------------------------------------------------------------------------
    void __fastcall TForm1::ClientRead(TObject *Sender,
          TCustomWinSocket *Socket)
    {
     Application->MessageBox("Client a recu ?","FCT", MB_OK);
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::portChange(TObject *Sender)
    {
    Client->Port =  port->Text.ToInt();
    Server->Port =  port->Text.ToInt();
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::PubClick(TObject *Sender)
    {
    TJPEGImage *jpg = new TJPEGImage();
    Graphics :: TBitmap *bmp = new Graphics :: TBitmap();
    TRect *rect = new TRect();
    TPicture *img = new TPicture();
     
    img->Bitmap->Height = Screen->Height;
    img->Bitmap->Width = Screen->Width;
    int scrw = Screen->Width, scrh = Screen->Height;
    HWND hwnd = GetDesktopWindow();
    HDC hDC = GetDC(hwnd);
    BitBlt(img->Bitmap->Canvas->Handle,0,0,scrw,scrh,hDC,0,0,SRCCOPY);
     
    try
    {
         jpg->Assign(img->Bitmap);
         jpg->CompressionQuality = 50;
         jpg->Assign(img->Bitmap);
         bmp->Width = jpg->Width -50;
         bmp->Height = jpg->Height -50;
         rect->Left = 0;
         rect->Top = 0;
         rect->Right = bmp->Width-1;
         rect->Bottom = bmp->Height-1;
         bmp->Canvas->StretchDraw(*rect,jpg);
     
         jpg->Assign(img->Bitmap);
         jpg->SaveToFile("c:\\img.jpg");
         jpg->Free();
         bmp->Free();
         img->Free();
     
    }catch(...){}
     
    ReleaseDC(hwnd,hDC);
     
    Pub->Picture->LoadFromFile("c:\\img.jpg");
    }
    //-------------------------------------------------------------------------
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    Connexion->Enabled = false;
    Server->Active = false;
    Client->Active = false;
    }
    //-------------------------------------------------------------------------
     
    UNIT1.H
     
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include "stdio.h"
    #include <ExtCtrls.hpp>
    #include <ScktComp.hpp>
    #include <jpeg.hpp>
    #include <Registry.hpp>
    #include <Dialogs.hpp>
    #include <Buttons.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:	// Composants gérés par l'EDI
            TGroupBox *GroupBox1;
            TEdit *Edit1;
            TButton *Button2;
            TEdit *Edit2;
            TButton *Connexion;
            TEdit *IpServeur;
            TGroupBox *GroupBox2;
            TImage *Pub;
            TServerSocket *Server;
            TClientSocket *Client;
            TEdit *Edit4;
            TGroupBox *GroupBox3;
            TEdit *Edit3;
            TLabel *Label2;
            TLabel *Label3;
            TEdit *Edit5;
            TLabel *Label4;
            TEdit *Edit6;
            TButton *Button3;
            TTimer *FCT;
            TRadioGroup *RadioGroup1;
            TLabel *Label5;
            TLabel *Label6;
            TRadioButton *RadioButton1;
            TRadioButton *RadioButton2;
            TLabel *info_send;
            TLabel *timer;
            TLabel *error;
            TEdit *port;
            TOpenDialog *OpenDialog1;
            TLabel *Label1;
            TButton *Button1;
            TLabel *Label7;
            void __fastcall Button2Click(TObject *Sender);
            void __fastcall ConnexionClick(TObject *Sender);
            void __fastcall ClientConnect(TObject *Sender,
              TCustomWinSocket *Socket);
            void __fastcall ClientDisconnect(TObject *Sender,
              TCustomWinSocket *Socket);
            void __fastcall ClientError(TObject *Sender,
              TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
              int &ErrorCode);
            void __fastcall ServerClientConnect(TObject *Sender,
              TCustomWinSocket *Socket);
            void __fastcall ServerClientError(TObject *Sender,
              TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
              int &ErrorCode);
            void __fastcall FCTTimer(TObject *Sender);
            void __fastcall Button3Click(TObject *Sender);
            void __fastcall ServerClientRead(TObject *Sender,
              TCustomWinSocket *Socket);
            void __fastcall RadioButton1Click(TObject *Sender);
            void __fastcall RadioButton2Click(TObject *Sender);
            void __fastcall ClientRead(TObject *Sender,
              TCustomWinSocket *Socket);
            void __fastcall portChange(TObject *Sender);
            void __fastcall PubClick(TObject *Sender);
            void __fastcall Button1Click(TObject *Sender);
    private:	// Déclarations utilisateur
     
            char buf2[5000];
    	FILE *FichierEnvoi;
            char buf[5000];
            FILE *FichierRecu;
     
            float sec,min,her;
            int SIZE;
            AnsiString bureau;
            void AfficheLocalIP();
     
    public:		// Déclarations utilisateur
            __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
     
    UNIT1.DMF
     
    object Form1: TForm1
      Left = 217
      Top = 213
      Width = 977
      Height = 565
      AutoSize = True
      BorderIcons = [biSystemMenu]
      Caption = 'Create Soft : CFT , Copie File Transfer ( Lan & Wan )'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object GroupBox1: TGroupBox
        Left = 0
        Top = 2
        Width = 313
        Height = 529
        Caption = 'Connexion'
        TabOrder = 0
        object Label5: TLabel
          Left = 8
          Top = 472
          Width = 104
          Height = 13
          Caption = 'Chemin de destination'
        end
        object Label6: TLabel
          Left = 10
          Top = 375
          Width = 66
          Height = 13
          Caption = 'Fichier source'
        end
        object Label1: TLabel
          Left = 10
          Top = 117
          Width = 73
          Height = 15
          Caption = 'IP PC Serveur'
          Font.Charset = ANSI_CHARSET
          Font.Color = clWindowText
          Font.Height = -13
          Font.Name = 'Times New Roman'
          Font.Style = []
          ParentFont = False
        end
        object Edit1: TEdit
          Left = 8
          Top = 401
          Width = 297
          Height = 21
          TabOrder = 0
          Text = 'D:\Documents and Settings\Végéta\Bureau\pub.bmp'
        end
        object Button2: TButton
          Left = 8
          Top = 434
          Width = 144
          Height = 26
          Caption = 'Lecture et copie sur disque '
          TabOrder = 1
          OnClick = Button2Click
        end
        object Edit2: TEdit
          Left = 8
          Top = 496
          Width = 297
          Height = 21
          TabOrder = 2
          Text = 'D:\Documents and Settings\Végéta\Bureau\pub2.bmp'
        end
        object Connexion: TButton
          Left = 8
          Top = 150
          Width = 289
          Height = 25
          Caption = 'Connexion'
          TabOrder = 3
          OnClick = ConnexionClick
        end
        object IpServeur: TEdit
          Left = 90
          Top = 115
          Width = 213
          Height = 21
          TabOrder = 4
          Text = '000.000.000.000'
        end
        object Edit4: TEdit
          Left = 8
          Top = 184
          Width = 292
          Height = 21
          ReadOnly = True
          TabOrder = 5
        end
        object GroupBox3: TGroupBox
          Left = 7
          Top = 228
          Width = 295
          Height = 133
          Caption = 'info-Client'
          Enabled = False
          TabOrder = 6
          object Label2: TLabel
            Left = 34
            Top = 25
            Width = 38
            Height = 13
            Caption = 'Ip Client'
          end
          object Label3: TLabel
            Left = 33
            Top = 61
            Width = 51
            Height = 13
            Caption = 'Host Client'
          end
          object Label4: TLabel
            Left = 33
            Top = 99
            Width = 48
            Height = 13
            Caption = 'Port Client'
          end
          object Edit3: TEdit
            Left = 97
            Top = 22
            Width = 165
            Height = 21
            TabOrder = 0
          end
          object Edit5: TEdit
            Left = 97
            Top = 58
            Width = 165
            Height = 21
            TabOrder = 1
          end
          object Edit6: TEdit
            Left = 97
            Top = 96
            Width = 165
            Height = 21
            TabOrder = 2
          end
        end
        object Button3: TButton
          Left = 165
          Top = 436
          Width = 139
          Height = 25
          Caption = 'Envoyer Fichier "FCT"'
          TabOrder = 7
          OnClick = Button3Click
        end
        object RadioGroup1: TRadioGroup
          Left = 8
          Top = 17
          Width = 297
          Height = 88
          Caption = 'Type'
          TabOrder = 8
        end
        object RadioButton1: TRadioButton
          Left = 20
          Top = 42
          Width = 61
          Height = 17
          Caption = 'Serveur'
          TabOrder = 9
          OnClick = RadioButton1Click
        end
        object RadioButton2: TRadioButton
          Left = 19
          Top = 75
          Width = 55
          Height = 17
          Caption = 'Client'
          Checked = True
          TabOrder = 10
          TabStop = True
          OnClick = RadioButton2Click
        end
        object port: TEdit
          Left = 142
          Top = 36
          Width = 73
          Height = 21
          TabOrder = 11
          Text = '7879'
          OnChange = portChange
        end
        object Button1: TButton
          Left = 112
          Top = 72
          Width = 161
          Height = 25
          Caption = 'deconnecter'
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clMaroon
          Font.Height = -11
          Font.Name = 'MS Sans Serif'
          Font.Style = []
          ParentFont = False
          TabOrder = 12
          OnClick = Button1Click
        end
      end
      object GroupBox2: TGroupBox
        Left = 318
        Top = 0
        Width = 651
        Height = 529
        Caption = 'Image'
        TabOrder = 1
        object Pub: TImage
          Left = 6
          Top = 45
          Width = 640
          Height = 480
          Stretch = True
          OnClick = PubClick
        end
        object info_send: TLabel
          Left = 72
          Top = 18
          Width = 138
          Height = 24
          Caption = 'Envoi Terminé'
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clMaroon
          Font.Height = -19
          Font.Name = 'MS Sans Serif'
          Font.Style = [fsBold]
          ParentFont = False
        end
        object timer: TLabel
          Left = 264
          Top = 16
          Width = 70
          Height = 24
          Caption = '00:00:00'
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -19
          Font.Name = 'MS Sans Serif'
          Font.Style = []
          ParentFont = False
        end
        object error: TLabel
          Left = 400
          Top = 16
          Width = 230
          Height = 24
          Caption = 'Error fichier destinataire '
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clMaroon
          Font.Height = -19
          Font.Name = 'MS Sans Serif'
          Font.Style = [fsBold]
          ParentFont = False
          Transparent = True
          Visible = False
        end
        object Label7: TLabel
          Left = 304
          Top = 272
          Width = 42
          Height = 13
          Caption = 'Clique içi'
        end
      end
      object Server: TServerSocket
        Active = False
        Port = 0
        ServerType = stNonBlocking
        OnClientConnect = ServerClientConnect
        OnClientRead = ServerClientRead
        OnClientError = ServerClientError
        Left = 376
        Top = 104
      end
      object Client: TClientSocket
        Active = False
        ClientType = ctNonBlocking
        Port = 7879
        OnConnect = ClientConnect
        OnDisconnect = ClientDisconnect
        OnRead = ClientRead
        OnError = ClientError
        Left = 344
        Top = 104
      end
      object FCT: TTimer
        Enabled = False
        Interval = 250
        OnTimer = FCTTimer
        Left = 464
        Top = 104
      end
      object OpenDialog1: TOpenDialog
        Filter = '*.bmp;*.jpg;*.*";'
        Options = [ofReadOnly, ofOverwritePrompt, ofHideReadOnly, ofShowHelp, ofAllowMultiSelect, ofExtensionDifferent, ofPathMustExist, ofFileMustExist, ofCreatePrompt, ofShareAware, ofNoReadOnlyReturn]
        Left = 360
        Top = 336
      end
    end

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 7
    Par défaut
    Merci énormément Bily.sdi!
    J'ai pris ton code, l'ai mis à ma sauce et ca marche!! Par contre, j'ai du directement mettre le client et le seveur en Active = true car la connexion ne se faisait pas autrement, ce qui est très louche...

    Sinon, Bily.sdi, encore une petite demande, je dois créer, tjs sous TCP, une socket en C (obligé) et un client sous builder comme pour le transfert de fichier. Je dois, du serveur, envoyer des données sur l'IHM du client quand ce dernier le demande. Donc le client, recois plusieurs données en meme temps (des char) pour les affiché sur l'IHM. Je ne sais pas s'il faut passer par du thread ou autre... Merci encore une fois de votre aide!!

  5. #5
    Membre expérimenté Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par défaut
    salut,

    non tu peux le faire sans thread , maintenant que tu vois comment ca marche
    je vais te preparer un petit soft client serveur qui communique simplement !
    il se peut que tu as besoin de savoir la provenance etc...

    je v utiliser la fonction "Vecteur" dans connexion !
    tu pourras repondre a des poste etc sans faire une grande recherche sur
    l'ip de destination !

    ca fait un petit temp , je vais la poster se soir ou demain !

    Pour les fichiers, si tu dois les envoyer sur un poste distant " WAN "
    la source que j'ai poster plus haut marche mais vaut mieux utiliser le protocole d'envoi si tu envois des gros fichiers pour eviter des pertes etc.. mais logiquement ca tourne sans problem , j'ai deja tester!

    A bientot

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 7
    Par défaut
    Merci pour ton aide Bily.sdi!
    Par contre, j'ai essayer de faire un serveur et un client séparé pour le transfert de fichier et je n'arrive pas à recevoir le fichier sur le serveur!! Ca pourrait venir d'où? Faut il rajouter des fonctions en plus de ce que tu m'a passé??

  7. #7
    Membre expérimenté Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par défaut
    salut,

    le 2iem code que j'ai poster envoi des fichiers d'un poste a l'autre en faisant
    une lecture binaire !

    je vais le mettre sur mon ftp ou peut ton les placer sur ce site ?

  8. #8
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 7
    Par défaut
    Bily, tu me parlais de vecteur quand je te disais qu'il fallait que je créé un serveur en C puis un client en C++ (sous builder) pour envoyer et recevoir des données. En fait, je ne sais pas si ds ce cas, je dois utiliser des threads, des vecteurs, des évènements, etc... pourrais tu m'éclairer, merci!!

  9. #9
    Membre expérimenté Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par défaut transfert fichier manuel
    regarde dans ce lien , j'ai poster un code

    http://www.developpez.net/forums/sho...d.php?t=302347

    @+

  10. #10
    Membre confirmé

    Profil pro
    Inscrit en
    Mars 2010
    Messages
    75
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2010
    Messages : 75
    Par défaut
    Citation Envoyé par Bily.sdi Voir le message
    regarde dans ce lien , j'ai poster un code

    http://www.developpez.net/forums/sho...d.php?t=302347

    @+
    J'aimerais savoir comment faire pour afficher l'objet TJPEGImage dans la Form.
    Sous Visual Studio C++, il existe les pictureBox qui sont assez simples à utiliser. Mais je travaille sous Borland car mon prof n'est plus tout jeune et demande qu'on utilise les API WIN32 et puis j'ai essayé la transformation bmp->jpeg de votre code sous VS, mais il ne connaît pas les types TBitmap, TJPEGImage, TRect etc. etc.

  11. #11
    Expert éminent
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    14 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 14 049
    Par défaut
    C'est quoi le rapport ?
    Pourquoi déterrer un vieux sujet de 3 ans sur du TCP\IP pour un sujet de Graphique ?

    TJPEGImage est un objet de conversion à coupler avec un TImage.Picture !
    voir les include jpeg et graphics (ou vcl.h)

    As-tu correctement chercher 30secondes avant de poser une question ?





    Merci Modo de déplacer mon message et celui de sunlover !
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

Discussions similaires

  1. Envoyer un fichier par TCP
    Par invictus25 dans le forum Débuter
    Réponses: 0
    Dernier message: 05/05/2011, 11h27
  2. Envoyer un fichier par TCP
    Par jejeapollo dans le forum Langage
    Réponses: 1
    Dernier message: 27/07/2010, 18h21
  3. Envoyer un fichier par email
    Par portu dans le forum Delphi
    Réponses: 3
    Dernier message: 30/05/2006, 11h02
  4. [Mail] Envoyer un fichier par mail
    Par Oberown dans le forum Langage
    Réponses: 3
    Dernier message: 24/10/2005, 15h55
  5. Réponses: 1
    Dernier message: 19/08/2003, 16h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo