Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Using TIdTCPClient and TIdTCPServer
| Subject: | Re: Using TIdTCPClient and TIdTCPServer |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 2 Oct 2006 13:34:06 |
"Mikael Lenfors" <mikael@lenfors.se> wrote in message
news:452113cf$1@newsgroups.borland.com...
> I thougth the Indy TCPClient and Indy TCPServer would do fine.
They will work fine for that.
> I tried the following:
Your code is using the components wrong. Use this code instead:
--- Application A ---
IdTCPClient.Connect;
try
IdTCPClient.SendCmd('Test', 250);
Tx := IdTCPClient.LastCmdResult.Text;
finally
IdTCPClient.Disconnect;
end;
--- Applicaton B ---
procedure TForm5.IdTCPServerExecute(AContext: TIdContext);
var
Txt: String;
begin
Txt := Trim(AContext.Connection.IOHandler.ReadLn);
AContext.Connection.IOHandler.Write('250 responsedata');
end;
With that said, if you are going to use SendCmd() on the client side, then
you should consider using TIdCmdTCPServer instead of TIdTCPServer on the
server side. That way you can process individual commands using less code
and more event handlers that you can assign at design-time, ie:
--- Applicaton B ---
// add an entry to the TIdCmdTCPServer.CommandHandlers collection,
// configure as desired, and then assign this as its OnCommand event
handler ...
procedure TForm5.CommandTest(ASender: TIdCommand);
begin
ASender.Reply.SetReply(250, 'responsedata');
end;
Gambit