AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi Indy - Server schickt Nachricht an alle Clients
Thema durchsuchen
Ansicht
Themen-Optionen

Indy - Server schickt Nachricht an alle Clients

Ein Thema von Nalincah · begonnen am 27. Jul 2004 · letzter Beitrag vom 28. Jul 2004
Antwort Antwort
Benutzerbild von XHelp
XHelp

Registriert seit: 12. Jul 2004
Ort: Duisburg
172 Beiträge
 
Delphi 6 Enterprise
 
#1

Re: Indy - Server schickt Nachricht an alle Clients

  Alt 27. Jul 2004, 23:12
http://www.indyproject.org/indy/demo...os_24Nov02.zip
Guck mal bei den beispielen... das ist TCPServer-Client Demo dabei. Hier ein ausschnitt:
Delphi-Quellcode:
procedure TServerFrmMain.ServerExecute(AThread: TIdPeerThread);
var
  ActClient, RecClient: PClient;
  CommBlock, NewCommBlock: TCommBlock;
  RecThread: TIdPeerThread;
  i: Integer;

begin
  if not AThread.Terminated and AThread.Connection.Connected then
  begin
    AThread.Connection.ReadBuffer (CommBlock, SizeOf (CommBlock));
    ActClient := PClient(AThread.Data);
    ActClient.LastAction := Now; // update the time of last action

    if (CommBlock.Command = 'MESSAGE') or (CommBlock.Command = 'DIALOG') then
    begin // 'MESSAGE': A message was send - forward or broadcast it
           // 'DIALOG': A dialog-window shall popup on the recipient's screen
           // it's the same code for both commands...

      if CommBlock.ReceiverName = 'then
      begin // no recipient given - broadcast
        Protocol.Lines.Add (TimeToStr(Time)+' Broadcasting '+CommBlock.Command+': "'+CommBlock.Msg+'"');
        NewCommBlock := CommBlock; // nothing to change ;-))

        with Clients.LockList do
        try
          for i := 0 to Count-1 do // iterate through client-list
     begin
            RecClient := Items[i]; // get client-object
            RecThread := RecClient.Thread; // get client-thread out of it
            RecThread.Connection.WriteBuffer(NewCommBlock, SizeOf(NewCommBlock), True); // send the stuff
          end;
        finally
          Clients.UnlockList;
        end;
      end
      else
      begin // receiver given - search him and send it to him
        NewCommBlock := CommBlock; // again: nothing to change ;-))
        Protocol.Lines.Add(TimeToStr(Time)+' Sending '+CommBlock.Command+' to "'+CommBlock.ReceiverName+'": "'+CommBlock.Msg+'"');
        with Clients.LockList do
        try
          for i := 0 to Count-1 do
          begin
            RecClient:=Items[i];
            if RecClient.DNS=CommBlock.ReceiverName then // we don't have a login function so we have to use the DNS (Hostname)
            begin
              RecThread:=RecClient.Thread;
              RecThread.Connection.WriteBuffer(NewCommBlock, SizeOf(NewCommBlock), True);
            end;
          end;
        finally
          Clients.UnlockList;
        end;
      end;
    end
    else
    begin // unknown command given
      Protocol.Lines.Add (TimeToStr(Time)+' Unknown command from "'+CommBlock.MyUserName+'": '+CommBlock.Command);
      NewCommBlock.Command := 'DIALOG'; // the message should popup on the client's screen
      NewCommBlock.MyUserName := '[Server]'; // the server's username
      NewCommBlock.Msg := 'I don''t understand your command: "'+CommBlock.Command+'"'; // the message to show
      NewCommBlock.ReceiverName := '[return-to-sender]'; // unnecessary

      AThread.Connection.WriteBuffer (NewCommBlock, SizeOf (NewCommBlock), true); // and there it goes...
    end;
  end;
end
Ich glaube mal, da ist das dabei, was du brauchst.
Alex
Von allen Dingen die mir verloren gegangen,
hab ich am meisten an meinem Verstand gehangen
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:55 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz