Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Feb : Re: TIdSimpleServer or TIdTCPServer

www.cryer.info
Managed Newsgroup Archive

Re: TIdSimpleServer or TIdTCPServer

Subject:Re: TIdSimpleServer or TIdTCPServer
Posted by:"Philip von Melle" (philip.vonmel..@globetrotter.de)
Date:23 Feb 2007 05:18:15

"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:

> There are no threads involved with TIdSimpleServer.  Like
> TIdTCPClient, it runs in the context of whichever thread is using it.
> TIdSimpleServer is derived from TIdTCPConnection, just like
> TIdTCPClient is, so it is a 1-to-1 connection, so you can read/write
> to TIdSimpleServer like you would with TIdTCPClient.  The only
> difference is that to establish the connection, you would call
> Listen() in TIdSimpleServer, whereas you call Connect() in
> TIdTCPClient.  You would also usually call BeginListen() before
> Listen() in order to know which port to tell B to connect to.

What would I need to call BeginListen() for? Isn't Listen() just enough ?
Do I need to call EndListen() and or Abort() ?

Yes, the requests are serialized. So would the code below be proper use
for the protocol described above (using TIdSimpleServer)?

  // A connects to B
  IdTCPClient.Connect;
  try
    with IdTCPClient.IOHandler do
    begin
      WriteBufferOpen;
      Write(Length(MyRequest));
      Write(MyRequest);
      WriteBufferClose;
    end;
    // A must handle intermediate requests from B
    IdSimpleServer := TIdSimpleServer.Create;
    try
      IdSimpleServer.BoundPort := 20007;
      try
        IdSimpleServer.Listen(1000);
        while IdSimpleServer.Connected do
        begin
          try
            with IdSimpleServer.IOHandler do
            begin
              MyTempResult := ReadString(ReadInteger());
              WriteBufferOpen;
              Write(Length(MyTempReply));
              Write(MyTempReply);
              WriteBufferClose;
            end;
          except
            on E: EIdConnClosedGracefully do
              ; // nothing
          end;
        end;
      except
        on E: EIdAcceptTimeout do
          ; // no temp replies
      end;
    finally
      IdSimpleServer.Free;
    end;
    // get result
    with IdTCPClient.IOHandler do
      MyResult := ReadString(ReadInteger());
  finally
    IdTCPClient.Disconnect;
  end;


Philip

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive