Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: Indy 9 TPC client/Server and CommandHandlers

www.cryer.info
Managed Newsgroup Archive

Re: Indy 9 TPC client/Server and CommandHandlers

Subject:Re: Indy 9 TPC client/Server and CommandHandlers
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 25 Sep 2007 12:26:53

"RandomAccess" <Not@TellingYou.com> wrote in message
news:46f94ecf$1@newsgroups.borland.com...

> Well, currently I set up the server to send the response automatically

That does not stop you from sending responses manually as well.  When the
SendReply() method is called in your code, the TIdCommand's PerformReply
property is set to False so the command handler's automated reply is not
sent as well.

> So,  All I need to do is to get the CommandHandler to send
> the appropriate data from the server (a stream) to the client.

You can't send streams (or any other kind of dynamic data) using the command
handler's properties in the Object Inspector by itself.  You must have
OnCommand event handlers to send the data, which (almost always, depending
on your protocol) means calls SendReply() directly before sending the data
afterwards.

> That's the bit I don't understand.  what does "read the additional
> data as needed"  mean?

It means reading the data like you normally would if you weren't using
command handlers, such as calling ReadStream().  For example:

    --- server ---

    procedure TForm1.IdTCPServer1CommandTest(ASender: TIdCommand);
    var
        Strm: TMemoryStream;
    begin
        Strm := TMemoryStream.Create;
        try
            // fill Strm, then...
            ASender.Reply.SetReply(200, 'Data follows');
            ASender.SendReply;
            ASender.Thread.Connection.WriteStream(Strm, True, True);
        finally
            Strm.Free;
        end;
    end;


    --- client ---

    procedure TForm1.Button1Click(Sender: TObject);
    var
        Strm: TMemoryStream;
    begin
        Strm := TMemoryStream.Create;
        try
            Client.SendCmd('Test', 200);
            Client.ReadStream(Strm, -1, False);
            Strm.Position := 0;
            // use Strm as needed ...
        finally
            Strm.Free;
        end;
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive