Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Looking for very basic indy 10 server examples

www.cryer.info
Managed Newsgroup Archive

Re: Looking for very basic indy 10 server examples

Subject:Re: Looking for very basic indy 10 server examples
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Thu, 24 Jan 2008 11:04:11

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:4798e02d$1@newsgroups.borland.com...

>    type
>        // VCL event handlers need to be methods of a class
>        TMyServerEvents = class
>        public
>            procedure ServerExecute(AThread: TIdPeerThread);
>        end;

Sorry, I didn't notice you were using Indy 10 instead:

    program ServerTest;

    {$APPTYPE CONSOLE}

    uses
        SysUtils, IdIOHandler, IdTCPConnection, IdContext, IdTCPServer;

    type
        TMyServerEvents = class
        public
            procedure ServerExecute(AContext: TIdContext);
        end;

    procedure TMyServerEvents.ServerExecute(AContext: TIdPeerThread);
    var
        S: String;
    begin
        S := AContext.Connection.IOHandler.ReadLn;
        WriteLn(Format('%s: %s', [AContext.Connection.Socket.Binding.PeerIP,
S]));
    end;

    var
        svr: TIdTCPServer;
        events: TMyServerEvents;

    begin
        svr := TIdTCPServer.Create(nil);
        try
            events := TMyServerEvents.Create;
            try
                svr.Port := 12345;
                svr.OnExecute := events.ServerExecute;
                svr.Active := True;
                try
                    // wait for some signal that the app should shut down...
                finally
                    svr.Active := False;
                end;
            finally
                events.Free;
            end;
        finally
            svr.Free;
        end;
    end.


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive