Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 12.12.05 21:36 
Also UGrohne hat mir ja zu UDP-Broadcast geraten. Und in o'rallys Tutorial hab ich gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
  ABinding: TIdSocketHandle);
var
   RecText: string;
begin
   SetLength(RecText, AData.Size);
   AData.ReadBuffer(PChar(RecText)^, AData.Size);
   ShowMessage(ABinding.PeerIP + ' hat "' + RecText + '" gesendet.');
end;


Ja könnt ihr mir mal bitte jede Codezeile erklären :flehan:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 13.12.05 00:12 
Ist eigentlich relativ einfach. Die Parameter ABinding und AData stehen einmal für den Sender und das gesendete Packet. Da die Methode ReadBuffer als Parameter einen Zeiger auf einen String erwartet, müssen wir diesen vorbereiten, nämlich die Länger setzen. Das wird in der ersten Zeile mit SetLength gemacht, dieser wird AData.Size lang gemacht.

In der zweiten Zeile werden dann eben von ReadBuffer AData.Size Zeichen aus dem Puffer gelesen und mit Hilfe des Zeigers auf RecText (den man mit PChar(RecText)^ bekommt) in den String gespeichert.

Jo, ABinding.PeerIP ist wohl selbst erklärend.

Hab versucht das so einfach wie möglich zu erklären ;-)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 16.12.05 21:59 
Also ist das Read-Ereignis alles? Oder was muss man da noch schreiben? Aus dem Tutorial von O'rally werd ich auch nich schlau. :cry:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
emteg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Mi 21.12.05 21:59 
du hast schonmal das gleiche tutorial verwendet wie ich : )
ich benutz das genau so in meinem programm LanChat2. Kannst auf der HP da auch den ganzen quelltext runterladen.

Um deine frage zu beantworten: ja, das ist das ganze on read ereignis. So liest du JEDE ankommende udp nachricht auf dem eingestellten port. Egal ob es sich dabei um broadcasts handelt oder nicht.

Auf diese weise epmfängst du strings die über UDP gesendet werden. Anstatt von ShowMessage kannst du auch ne procedure dranhängen, welche die nachrichten analysiert und z.B. einen chat daraus baut. (Das ist mit udp ziemlich einfach: einfach jede nachricht broadcasten und eventuell einen nicknamen durch ein trennzeichen von der nachricht abtrennen und fertig.)

Wichtig ist, dass du ABinding.PeerIP verwendest und nicht ABinding.IP - weil nur im ersten fall erhälst du die adresse vom absender. (wofür ist eigentlich das letzte da?)

Was hast du denn noch für probleme mit dem UDP? Fragen dazu einfach an mich :)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 22.12.05 15:02 
@ emteg:

Danke für deine Hilfe. ALso ich will mit UDP (- Broadcast) eine Liste aller im LAN vorhandenen Pcs bekommen. Ist das möglich? Wenn ja, gibst du mir Tipps dazu?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
emteg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 23.12.05 16:22 
nur, wenn auf jedem pc ein client deiner software läuft. wenn du das nicht willst, musst du entweder die windowsAPI verwenden oder dir selber was basteln.
ich kann dir nur helfen, wenn auf jedem pc ein client läuft.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 24.12.05 19:07 
Am besten wäre ein WIN-API funktion aber bis jetzt hab ich keine gefunden :cry:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot