Bonjour,
Je développe actuellement une application en c++ avec Borland 2006. J'utilise le composant "IdUDPServer" et "IdUDPClient". Voici les codes sources :
Serveur :
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 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::IdUDPServer1UDPRead(TObject *Sender, TStream *AData, TIdSocketHandle *ABinding) { Memo1->Lines->Add(IdUDPServer1->ReceiveString()); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { IdUDPServer1->DefaultPort = StrToInt(EdPort->Text); IdUDPServer1->Active = true; Form1->Caption = IdUDPServer1->LocalName + ":" +IdUDPServer1->DefaultPort; ClientHeight = 340; } //---------------------------------------------------------------------------
Avec ce code tout fonctionne dans mon réseau local. Le seule souci c'est que je dois envoyer deux fois mon texte comme vous pouvez le voir. Je voudrais savoir pourquoi je dois justement envoyer deux fois....
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 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString texte; texte = IdUDPClient1->LocalName + ":" + EdTexte->Text; IdUDPClient1->Send(texte); IdUDPClient1->Send(texte); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { IdUDPClient1->Host = EdIpServeur->Text; IdUDPClient1->Port = StrToInt(EdPort->Text); IdUDPClient1->Active = true; ClientHeight = 340; Form1->Caption = IdUDPClient1->LocalName + ": " + IdUDPClient1->Port; } //---------------------------------------------------------------------------
Merci de votre aide![]()
Partager