Thema: Delphi Indy TCP Problem.

Einzelnen Beitrag anzeigen

danu1104

Registriert seit: 4. Dez 2006
75 Beiträge
 
Delphi 2006 Personal
 
#3

Re: Indy TCP Problem.

  Alt 25. Mär 2009, 08:24
Okay, ich werds Probieren, kann mir evtl jemand auch sagen warum ich immer diese meldung habe sobald ich was zum server schicke etc ... also die Meldung "Verbindung erfolgreich geschlossen" ... Mich nervt das einwenig.. ich würde ja aufgrund desen lieber versuchen Winsocks zu nutzen aber der gibt Fehlercodes raus womit keiner was anfangen kann ( ich zumindest ). SInd das chikanen oder habe ich einfach nur was falsch gemacht? Also Ich habe aner Komponente nix weiteres ausser Port angaben geändert, brauche ich evtl einen ThreadMgr oder sonstiges um den server ohne ewigen Spam laufen zu lassen

Ich sag mal ist ja nicht gerade toll wenn man ewig schilder weg drückt nur weil indy meint ewig die verbindung zu trennen, vorallem kommt das sehr böse wenn es sich dann noch um ein Spiel handelt.


Ich lege einfach mal den Server - OnExecute code bei:

Delphi-Quellcode:
procedure TForm1.DBServerExecute(AContext: TIdContext);
Var S:String;
    Val:Integer;
    sVal:String;
begin
if BusyGRP.ItemIndex = 0 then Exit;
if AContext.Connection.Connected then
begin
try
   InCom.DelimitedText:=AContext.Connection.IOHandler.ReadLn();
  finally
if InCom.Strings[0] = 'GETEXPthen
 begin
   sval:=RunCommand('GET '+InCom.Strings[1]+':'+'gexp');
   AContext.Connection.IOHandler.WriteLn('GEXP'+','+sVal);
  end;
if InCom.Strings[0] = 'GETPWDthen
 begin
   sval:=RunCommand('GET '+InCom.Strings[1]+':'+'Password');
   AContext.Connection.IOHandler.WriteLn('PWD'+','+sVal);
  end;
if InCom.Strings[0] = 'GETHEALthen
 begin
   val:=StrToInt(RunCommand('GET '+InCom.Strings[1]+':'+'aheal'));
   AContext.Connection.IOHandler.WriteLn('HEAL'+','+IntToStr(Val));
  end;
if InCom.Strings[0] = 'GETAPNTSthen
 begin
   val:=StrToInt(RunCommand('GET '+InCom.Strings[1]+':'+'apnts'));
   AContext.Connection.IOHandler.WriteLn('APNTS'+','+IntToStr(Val));
  end;
if InCom.Strings[0] = 'GETSTRthen
 begin
   val:=StrToInt(RunCommand('GET '+InCom.Strings[1]+':'+'astr'));
   AContext.Connection.IOHandler.WriteLn('STR'+','+IntToStr(Val));
  end;
 if InCom.Strings[0] = 'SETAPNTSthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'apnts'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+' ';
    usrlog.SelText:=''+' hat '+InCom.Strings[2]+' apnts.'+slinebreak;
    try
     RunCommand(S);
    except
     usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
  if InCom.Strings[0] = 'SETSTRthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'astr'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+'';
    usrlog.SelText:=''+' hat jetzt '+InCom.Strings[2]+' STR.'+slinebreak;
    try
     RunCommand(S);
    except
     usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
  if InCom.Strings[0] = 'SETHEALthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'aheal'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+'';
    usrlog.SelText:=''+' hat jetzt '+InCom.Strings[2]+' Heal.'+slinebreak;
   try
     RunCommand(S);
    except
     usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
  if InCom.Strings[0] = 'SETDEFthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'def'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+'';
    usrlog.SelText:=''+' hat jetzt '+InCom.Strings[2]+' Def.'+slinebreak;
   try
     RunCommand(S);
    except
    usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
  end;
  if InCom.Strings[0] = 'SETDMGthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'dmg'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+'';
    usrlog.SelText:=''+' macht jetzt '+InCom.Strings[2]+' Dmg.'+slinebreak;
   try
     RunCommand(S);
    except
     usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
 if InCom.Strings[0] = 'SETEXPthen
   begin
    S:='SET '+InCom.Strings[1]+':'+'gexp'+':'+InCom.Strings[2];
    usrlog.SelAttributes.Color:=clblue;
    usrlog.SelText:=''+'»»'+' ';
    usrlog.SelAttributes.Color:=clred;
    usrlog.SelText:=''+InCom.Strings[1]+'';
    usrlog.SelText:=''+' hat jetzt '+InCom.Strings[2]+' Exp von ???.'+slinebreak;
   try
     RunCommand(S);
    except
     usrlog.SelAttributes.Color:=clred;
     usrlog.SelAttributes.Style:=[];
     usrlog.SelText:=''+'»»'+' ';
     usrlog.SelAttributes.Color:=clblue;
     usrlog.SelText:=''+' Fehlgeschlagen.'+''+slineBreak;
    end;
   end else
 end;
end;
und hier die Client Source zur übertragung von Infos:

Delphi-Quellcode:
Function GetInfo(Typ:String):Integer;
Var SRV:TStringlist;
begin
Form1.DBCLient.Address:='localhost';
 If not Form1.DBCLient.Active then Form1.DBCLIENT.Active:=true;
 SRV:=Tstringlist.Create;
 SRV.Delimiter:=',';
  try
   Form1.DBClient.Socket.SendText('GET'+Typ+','+Form1.Username);
  finally
    Srv.DelimitedText:=Form1.DBClient.Socket.ReceiveText();
   if Srv.Strings[0] = TYP then
    Result:=StrToInt(Srv.Strings[1]);
  end;
end;

Function GetInfoS(Typ:String):String;
Var SRV:TStringlist;
begin
Form1.DBCLient.Address:='localhost';
 If not Form1.DBCLient.Active then Form1.DBCLIENT.Active:=true;
 SRV:=Tstringlist.Create;
 SRV.Delimiter:=',';
  try
   Form1.DBClient.Socket.SendText('GET'+Typ+','+Form1.Username);
  finally
    Srv.DelimitedText:=Form1.DBClient.Socket.ReceiveText;
   if Srv.Strings[0] = TYP then
    Result:=Srv.Strings[1];
  end;
end;

Procedure ModifyInfo(Typ:String;Points:Integer); overload;
begin
Form1.DBCLient.Address:='localhost';
  If not Form1.DBCLient.Active then Form1.DBCLIENT.Active:=true;
  Form1.DBClient.Socket.SendText('SET'+TYP+','+Form1.Username+','+IntToStr(Points));
end;

Procedure ModifyInfo(Typ:String; Str:String); overload;
begin
Form1.DBCLient.Address:='localhost';
 If not Form1.DBCLient.Active then Form1.DBCLIENT.Active:=true;
  Form1.DBClient.Socket.SendText('SET'+TYP+','+Form1.Username+','+Str);
end;
Edit: ähm ja, ich habe überall in den abfragen das ELSE vergessen, ob das jetzt der grund ist idknow, aber ich kanns mir net vorstellen da Indy sogar bei meinen Messanger Projekt son terz gemacht hat und daher ...

RunCommand(); ist nichts besonderes, mit der Function Simuliere ich nur eine DB im format einer INI datei, SET DATEI&SECTION:IDENT:VALUE (Werte schreiben / setzen) GET DATEI&SECTION:IDENT ...auslesen
Daniel
  Mit Zitat antworten Zitat