Einzelnen Beitrag anzeigen

Jackie1983

Registriert seit: 12. Mär 2007
486 Beiträge
 
#14

AW: TIdTCPServer / TIdTCPClient => Ping - Pong

  Alt 21. Jun 2010, 17:35
hi,

ok wenn das nicht zu viel ist, mache ich das gerne.
Ist alles im Thread

Client Send
Delphi-Quellcode:
  if not fclient.Connected then exit;

// fcs.Enter;
  try
    try
      fClient.WriteLn(ACmd.SendFrames);
    except
    end;
  finally
// fcs.Leave;
  end;
Client Execute
Delphi-Quellcode:
  fClient := TIdTCPClient.Create(nil);
  fClient.ReadTimeout := 500;
  fClient.Host := fHost;
  fClient.Port := FPort;

  while not Terminated do begin
    //Prüfen ob Client Online
    if not fClient.Connected then
    begin
      try
        fClient.Connect(500);
      except
        //beep;
      end;
    end;

    //Ping senden
    (*
    if fClient.Connected then begin
      cmd := TCommandHandling.Create(CMDPing);
      try
        fCS.Enter;
        try
          fClient.WriteLn(cmd.SendFrames);
          msg := '';
          msg := fClient.ReadLn;
        finally
          fCS.Leave;
        end;
        if msg = '' then
          fClient.Disconnect;
      except
        fClient.Disconnect;
      end;
    end;
    *)


    //Text empfangen
    if fClient.Connected then begin
// fCS.Enter;
      try
        try
          IsTimeout := true;
          msg := fClient.ReadLn;
          IsTimeout := false;
        except
          //Timeout
          IsTimeout := True;
        end;

        if not IsTimeout then begin
          cmd := TCommandHandling.Create(CMDNone);
          try
            cmd.SetFrames(msg);
            try
              if Assigned(fOnRead) then
                fOnRead(cmd);
            except
              //Fehler in OnRead abfangen
            end;
          finally
            FreeAndNil(cmd);
          end;
        end;
      finally
// fCS.Leave;
      end;
    end;
    sleep(100);
  end;
  Mit Zitat antworten Zitat