Autor Beitrag
F.Art
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Mo 21.06.04 18:59 
Wie kann ich nur einen bestimmten Client vom Server disconnecten?
Ich benutze SocketClient und Server.
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 08:54 
Hier ein kleines Beispiel:
ausblenden 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:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  if Socket.ReceiveText = 'kick' then
    Socket.Close;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if ClientSocket1.Socket.Connected then
    ClientSocket1.Socket.SendText('kick');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ServerSocket1.Active := True;
  ClientSocket1.Active := True;
end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ShowMessage('Kicked!')
end;
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Di 22.06.04 11:07 
Werden so nicht alle Client gekickt?
Ich möchte das nur ein bestimmter gekickt wird.
Es soll auch automatisch gehen, wer das falsche Passwort eingibt kommt nicht rein.
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 11:26 
Schauen wir uns doch mal die entscheidende Prozedur genau an...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;   
  Socket: TCustomWinSocket);   
begin   
  if Socket.ReceiveText = 'kick' then //hier wird der Text aus der Verbindung zu einem Client gelesen...
    Socket.Close; // und hier wird genau diese Verbindung geschlossen.
end;


Das ganze passiert also vollkommen gekapselt, der Parameter Socket ist hier für genau die Verbindung, die das Event verursacht hat.
Der ServerSocket hat also eine ganze Liste von Sockets (alle Client-Verbindungen), zu finden unter ServerSocket1.Socket.Connections... Damit kann man sogar andere Verbindungen schließen oder Botschaften vom Server an alle oder bestimmte Clients verteilen...
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Di 22.06.04 12:38 
ausblenden Delphi-Quelltext
1:
2:
3:
if 'Passwort='+Passwort=Befehle then else
   if 'Passwort=Admin'=Befehle then else
      if 'Passwort='+Passwort=Befehle then else Socket.Close;


So werden nun die PWs gescheckt aber die weiteren Befehle werden dann auch gefilter.
Wie bekomme ich das nun hin das er nur einmal nach dem PWs abfragt?
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 12:41 
Meinen Vorschlag dazu gibt's in diesem Thread! :wink:
hallo
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 450

WIN XP, SuSE 9.3
D3 Prof, D6 Pers, 2005 Pers
BeitragVerfasst: Di 22.06.04 12:45 
Oder machs so:
Wenn einer eine Nachricht schreibt, wird ja auch der Name gesendet.
Dann überprüfe halt einfach die Namen die schreiben dürfen, und wer gekikt ist, dem seine Beiträge werden erst gar nicht angezeigt

_________________
Der beste je Programmierte Trojaner: Windows XP
Wäre es nicht adequat, den Usus heterogener Termini zu minimieren?
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Di 22.06.04 13:16 
Moin!

Und wenn du auf dem ServerSocket Programm die Verbindung schliessen willst, dann kannst du auch einfach direkt dort bei der jeweiligen Socket Connection des Users ein .Close() reinhauen, dann ist auch wech und man braucht ihm nicht extra noch eine Message bzw. einen Befehl zu schicken...

MfG
Muetze1
F.Art Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 434



BeitragVerfasst: Di 22.06.04 14:07 
@ Stevie
Dein Beitrag hatte ich noch garnicht gelesen, werde ich mal nachholen.
FrEaKY
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 235


D7
BeitragVerfasst: Di 22.06.04 14:38 
Server.ActiveConnections[].Disconnect (?)
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Di 22.06.04 14:41 
FrEaKY hat folgendes geschrieben:
Server.ActiveConnections[].Disconnect (?)

Nicht wirklich... :lol:
Muetze1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 346



BeitragVerfasst: Di 22.06.04 15:04 
Moin!

Um auf meinen Beitrag zurück zu kommen:

ausblenden Quelltext
1:
ServerSocket1.Socket.Connections[].Close();					


MfG
Muetze1