Autor Beitrag
DorJo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Sa 02.06.07 13:36 
Hy @ all,
ich bin neu hier und hab da mal eine Frage. Ich wollte gern ein Programm schreiben das wie folgt aufgebaut ist. Zum einen baut es einen Server auf, und auf einem anderen Rechner im Lan-Netz möchte ich das das Programm automatisch diesen Server erkennt und mit ihm Verbindung aufnimmt. Dann soll eigentlich nichts weiter passieren als ein paar Daten ausgetauscht werden.
Ich hab mich da schon ein bisschen belesen und anscheinend brauche ich die IdTCPID Komponente dafür... also habe mir www.dsdt.info/tutorials/indy/?page=2 dieses Tutorial mal angeschaut aber schon der erste Schritt hat nicht funktioniert.

Hat irgendjemand Ahnung wie man mein oben beschriebenes Problem lösen könnte?!
Ich wäre euch sehr verbunden!

Danke schon ma im vorraus!

Dor Jo
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 02.06.07 23:33 
Der einfache Weg in diesem Fall (mal abgesehen von der Komponente) wäre die Verwendung eines UDP-Broadcasts im Netz, den ein Client absendet, um nach einem Server zu suchen. Der Server seinerseits würde dann einfach antworten: "Hier bin ich" woraufhin der Client eine Verbindung mit dem Server aufnimmt (entweder über TCP ODER weiterhin über UDP ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 03.06.07 14:48 
Moin!

Schau mal hier, vielleicht kommst du damit weiter. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Mo 04.06.07 16:43 
Danke erst mal für die Antworten. Aber wenn ich alles richtig verstenden hab geht das doch mit diesem UDP-Broadcast nicht, gleichzeitig mehrere Sitzungen aufzumachen, oder?!
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mo 04.06.07 16:53 
UDP-Broadcasts gehen an alle.
Du müsstest dann als Client einen Broadcast senden, den die Server beantworten, sodass du eine Serverliste aufbauen kannst, mit der du dann anstellen willst, wozu du gerade lustig bist.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 04.06.07 17:08 
Moin!

user profile iconDorJo hat folgendes geschrieben:
Aber wenn ich alles richtig verstenden hab geht das doch mit diesem UDP-Broadcast nicht, gleichzeitig mehrere Sitzungen aufzumachen, oder?!

Das UDP-Protokoll hat keine Sitzungen, das ist ja der Witz daran. :mahn: ;) Vielleicht hilft die Vorstellung, dass die UDP-Pakete wie Telegramme gesendet werden; es gibt keine Rückmeldung über den Empfang und auch keinen "Rückkanal" (vollduplex) wie bei TCP, statt dessen kannst du halt auch Pakete an die Absenderadresse schicken.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Mo 11.06.07 21:35 
Hy nochma...
also ich hab jetz euern Rat weitestgehend befolgt. Ich hatte mir das dann so gedacht:
1. Man kann halt mit ein und demselben Programm einen Server bzw. einen Client einrichten.
1.1 Für den Server sieht das dann so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  
IdTCPServer1.Active := True;
ServerIp.caption:=IdIPWatch1.LocalIP;
rechnername.Caption:=IdIPWatch1.LocalName;
port.Caption:=Inttostr(UDP_Poker_Port);
UdpSockUtil1.LocalPort := StrToIntDef(Port.caption,UDP_PORT);
UdpSockUtil1.RemotePort := UdpSockUtil1.LocalPort;
UdpSockUtil1.Open;

1.2. Und so für den Client:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
UdpSockUtil1.LocalPort := StrToIntDef(Port.caption,UDP_PORT);
UdpSockUtil1.RemotePort := UdpSockUtil1.LocalPort;
UdpSockUtil1.Open;
UdpSockUtil1.BroadcastText(APP_ID+#13
'Client'+#13
IdIpWatch1.LocalIP+#13+
Nickname.Text+#13);
IdTCPClient1.BoundIP:=IdIpWatch1.LocalIp;
IdTCPClient1.BoundPort:=UDP_Poker_Port;


1.4 So und das Ereignis onreceive sieht denn so aus:
ausblenden volle Höhe Delphi-Quelltext
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:
procedure TForm1.UdpSockUtil1Receive(Sender: TObject);
var vonIP: in_addr;
    Data: TStringList; 
    serverip : string;
begin
{Narses Code. Teilweise verändert!}
Data := TStringList.Create;
try
Data.Text := UdpSockUtil1.ReceiveText(vonIP); 
if (Data.Count > 1then 
if (Data.Strings[0] = APP_ID) then begin 
  ShowMessage(Data.Strings[1]);
  if (server=true) then
  begin
    if (Data.Strings[1] = 'Client'then
    begin
      UdpSockUtil1.BroadcastText(APP_ID+#13
      'Server'+#13
      IdIpWatch1.LocalIP+#13);
    end;
  end else if (server=false) then
  begin
    if (Data.Strings[1] = 'Server'then
    begin
     serverip:=Data.Strings[2];
     IdTCPClient1.Host:=serverip;
     IdTCPClient1.Connect(100);
     users_client.AddItem(serverip, users_client);
    end;
  end;
end;
finally
Data.Free;
end;
end;


Bloß wenn ich das denn ausführe,... da geht das ni! Das Programm auf dem anderen Rechner erhält überhaupt kein Broadcast!!! Weiß jemand warum?!?!?

Danke schon ma im vorraus!!!

MfG


Dor Jo
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 11.06.07 22:54 
Moin!

user profile iconDorJo hat folgendes geschrieben:
Bloß wenn ich das denn ausführe,... da geht das ni! Das Programm auf dem anderen Rechner erhält überhaupt kein Broadcast!

Hast du mal das UDP-Chat-Beispielprogramm aus dem Tut probiert? Klappt das in deinem LAN? Firewall-Probs? :|

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Mo 11.06.07 22:58 
@ Narses: Ja das funktioniert ohne Probleme! Weißt du worans liegen könnte?!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 11.06.07 23:02 
Moin!

Füg mal das ShowMessage ein, was passiert?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.UdpSockUtil1Receive(Sender: TObject);
var vonIP: in_addr;
    Data: TStringList; 
    serverip : string;
begin
{Narses Code. Teilweise verändert!}
Data := TStringList.Create;
try
Data.Text := UdpSockUtil1.ReceiveText(vonIP); 
ShowMessage(Data.CommaText);
if (Data.Count > 1then 
if (Data.Strings[0] = APP_ID) then begin 
  ShowMessage(Data.Strings[1]);
  if (server=true) then
  begin
//...
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Mo 11.06.07 23:18 
@ Narses: Da kommt "POKER,Client,192.168.178.66,Nickname"... Eigentlich das was kommen sollte!

Was mich eigentlich so verwundert:
ausblenden Delphi-Quelltext
1:
2:
if (Data.Strings[0] = APP_ID) then begin 
  ShowMessage(Data.Strings[1]);
eigentlich müsste er hier schon was anzeigen. Und zwar auf beiden Rechnern! Zeigt aber bloß was auf dem Clientrechner an :( Woran könnte das liegen!

Ps.: Ich bin ma mitm Debugger durchgegangen, bei dem Server. Wenn der Client ne Nachricht schickt, kommt die glaub ich gar ni beim Server an! Kann das sein?! (@ Narses: Du hast glaub ich die Prozedur SendText genommen! Ich hab BroadcastText verwendet! Kann es vielleicht daran liegen?!)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 11.06.07 23:28 
Moin!

user profile iconDorJo hat folgendes geschrieben:
Eigentlich das was kommen sollte!

OK, also kein Netzwerk-/Komponenten-Problem. ;)

user profile iconDorJo hat folgendes geschrieben:
eigentlich müsste er hier schon was anzeigen. Und zwar auf beiden Rechnern! Zeigt aber bloß was auf dem Clientrechner an :( Woran könnte das liegen!

Ps.: Ich bin ma mitm Debugger durchgegangen, bei dem Server. Wenn der Client ne Nachricht schickt, kommt die glaub ich gar ni beim Server an! Kann das sein?!

Ich fürchte, das Problem ist dein Programm-"Konzept"... :?

user profile iconDorJo hat folgendes geschrieben:
(@ Narses: Du hast glaub ich die Prozedur SendText genommen! Ich hab BroadcastText verwendet! Kann es vielleicht daran liegen?!)

Nein, sehr wahrscheinlich nicht.

Bist du sicher, dass du dein Protokoll sauber genug geplant hast? :| :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Di 12.06.07 08:39 
Zitat:
Bist du sicher, dass du dein Protokoll sauber genug geplant hast? :| :nixweiss:

Naja... also... eigentlich wenn ich dein Tutorial richtig verstanden habe, sende ich doch ein Broadcast. Da müsste es doch also zumindest auf dem anderen Rechner ankommen, oder?! Das tut es aber schon mal nicht :cry: . Weil ich mein, eigentlich sollte er sofort, wenn er eine Nachricht empfängt mir die 2. Zeile als Message ausgeben... das tut er aber nur beim CLient und ni beim SErver!!!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.06.07 09:30 
Moin!

user profile iconDorJo hat folgendes geschrieben:
wenn ich dein Tutorial richtig verstanden habe, sende ich doch ein Broadcast. Da müsste es doch also zumindest auf dem anderen Rechner ankommen, oder?!

Ja, das würde ich sagen - wenn du keinen anderen Fehler drin hast. ;)

user profile iconDorJo hat folgendes geschrieben:
Das tut es aber schon mal nicht :cry: . Weil ich mein, eigentlich sollte er sofort, wenn er eine Nachricht empfängt mir die 2. Zeile als Message ausgeben... das tut er aber nur beim CLient und ni beim SErver!!!

Dann wirst du wohl den Fehler eingrenzen müssen, Testausgaben, nur grundlegende Codeteile, Rest rauskommentieren, Testprogramm, was nur Daten überträgt, etc. pp. :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Di 12.06.07 17:30 
@ Narses: Was hat das eigentlich in deinem Tutorial mit der Applikations-Id zu bedeuten?!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 12.06.07 17:50 
Moin!

user profile iconDorJo hat folgendes geschrieben:
Was hat das eigentlich in deinem Tutorial mit der Applikations-Id zu bedeuten?!

Applikation-ID = Anwendungs-Kennung :idea:
Ist dazu da, um herauszufinden, ob der Sender eine kompatible Anwendung ist (ein Server oder ein Client, mit dem ich auch reden möchte).

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Di 12.06.07 18:01 
Zitat:
Applikation-ID = Anwendungs-Kennung :idea:
Ist dazu da, um herauszufinden, ob der Sender eine kompatible Anwendung ist (ein Server oder ein Client, mit dem ich auch reden möchte).

Hm, das brauch ich doch aber ni oder?!
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: Di 12.06.07 18:52 
user profile iconDorJo hat folgendes geschrieben:
Zitat:
Applikation-ID = Anwendungs-Kennung :idea:
Ist dazu da, um herauszufinden, ob der Sender eine kompatible Anwendung ist (ein Server oder ein Client, mit dem ich auch reden möchte).

Hm, das brauch ich doch aber ni oder?!

Sollte man IMHO immer verwenden. Woher willst du wissen, ob am anderen Ende am entsprechenden Port der richtige Server läuft? Vielleicht horcht da ein ganz anderes Programm, das dann Fehler produziert...

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
DorJo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 139



BeitragVerfasst: Di 12.06.07 22:14 
ALLES GLOAR!!!! Hab mein Fehler gefunden. :oops: Narses hatte recht, ich hatte da was nicht recht durchdacht, wodurch der server und der client auf unterschiedlichen Ports lauschten... :oops: :autsch: :eyecrazy: Danke trotzdem für eure Hilfe!!!
:zustimm: :rofl: :flehan: :flehan: :beer: