Re: How to send a message from my Delphi-Appli to my Delphi-Service with Indy

Giganews Newsgroups
Subject: Re: How to send a message from my Delphi-Appli to my Delphi-Service with Indy
Posted by:  David (lokiwashe…@yahoo.co.nz)
Date: Tue, 31 May 2005

The easiest way which I have used for some of my services is to put a
TIDTCPServer in the service
and then in its' OnExecute event you handle commands from the client(s) and
send responses

Something like this (from memory) :-

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
    var
        InCmd: string;
    begin
// this example expectes to receive a command fro the client, it then sends
back an "OK" or "FAILED" and
// waits for a new command
        while AContext.Connection.Connected do
        begin
            InCmd := AContext.Connection.IOHandler.ReadLn;
            if InCmd = 'GO' then
            begin
// send a mesage to the main thread to start the process TIdSycn, or
Synchronize, or PostMessage, TCritialSection, up to you really
// keep this connection alive, and then do a
              AContext.Connection.IOHandler.Write('OK'); // or ('FAILED') if
you like then
// when the process has completed, or if you need to tell the client
something
            end
            else if InCmd = 'STOP' then
            begin
// send a mesage to the main thread to start the process
// keep this connection alive, and then do a
              AContext.Connection.IOHandler.Write('OK'); // or ('FAILED') if
you like then
// when the process has completed, or if you need to tell the client
something
            end
            else if InCmd = 'QUIT' then
            begin
                AContext.Connection.IOHandler.Write('BYE'); // closing
connection
// disconnect the client
                AContext.Connection.Disconnect;
            end;
        end; // loops back and waits for a new command from the client
    end;

On the client you would have  TIDTCPClient.
The client would do a
Write('GO')
then a ReadLn,
then a Write('QUIT')

hth

"Willi Kühnis" <wkuehn…@bluewin.ch> wrote in message
news:F5B2762AC3CCE240wkuehn…@bluewin.ch...
> Hi,
>
> I would like to send a message from my D5-appli to my D7-Service
>
> My appli has to inform the service, that he should start his job.
> Maybe at the end the service also could inform the appli, that it's
> finished.
>
> Can it be done with TCP/IP-Sockets ?
> What's the easiest way?
> Is there somewhere a example ?
>
> Thanks
> Willi

Replies

In response to

How to send a message from my Delphi-Appli to my Delphi-Service with Indy posted by Willi Kühnis on Mon, 30 May 2005