Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: Detect when command complete
| Subject: | Re: Detect when command complete |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 3 May 2006 21:30:51 |
"Jon" <JonJacobs@comcast.net> wrote in message
news:4459798b$1@newsgroups.borland.com...
> I do have the appropriate ReplyTexts value.
You still should not be accessing the ReplyTexts directly to begin with.
Asside from that, the fact that you have to include a line number as a
parameter to the command suggests a poorly designed protocol to begin with.
If you are sending the lines in order from the client, then there is no need
to specify the line numbers at all. Like I mentioned before, you should not
be sending the lines individually as separate commands to begin with. Send
them in a single command, ie:
--- server ---
// set the TIdCommandHandler.ReplyNormal.NumericCode to 200 beforehand
procedure TForm1.HandleSaveCommand(ASender: TIdCommand);
var
Lines: TStringList;
begin
Lines := TStringList.Create;
try
ASender.Thread.Connection.WriteLn('250 Send the lines now');
ASender.Thread.Connection.Capture(Lines);
// save Lines as needed ...
finally
Lines.Free;
end;
end;
--- client ---
var
Lines: TStringList;
begin
Lines := TStringList.Create;
try
// fill Lines as needed, then ...
IdTCPClient1.SendCmd('SAVE', 250);
IdTCPClient1.WriteRFCStrings(Lines);
IdTCPClient1.GetResponse(200);
finally
Lines.Free;
end;
end;
Alternatively:
--- server ---
// set the TIdCommandHandler.ReplyNormal.NumericCode to 200 beforehand
procedure TForm1.HandleSaveCommand(ASender: TIdCommand);
var
File: TFileStream;
begin
File := TFileStream.Create('c:\folder\file.ext', fmCreate);
try
try
ASender.Thread.Connection.WriteLn('250 Send the file now');
ASender.Thread.Connection.ReadStream(File);
finally
File.Free;
end;
except
DeleteFile('c:\folder\file.ext');
raise;
end;
end;
--- client ---
var
File: TFileStream;
begin
// use any TStream source you want...
File := TFileStream.Create('c:\another folder\file.ext', fmOpenRead
or fmShareDenyWrite);
try
IdTCPClient1.SendCmd('SAVE', 250);
IdTCPClient1.WriteStream(File, True, True, 0);
IdTCPClient1.GetResponse(200);
finally
File.Free;
end;
end;
Gambit