Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : Re: Connections of a TIdCcmTCPServer

www.cryer.info
Managed Newsgroup Archive

Re: Connections of a TIdCcmTCPServer

Subject:Re: Connections of a TIdCcmTCPServer
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 26 Mar 2008 09:50:16

"Moore" <moore@hotmail.com> wrote in message
news:47ea1c65$1@newsgroups.borland.com...

> what's wrong eith this code? it either blocks the app or sends an AV:

You are calling LockList() too many times.  Every call to LockList()
requires an equal number of calls to UnlockList(), but you are not doing
that.  Thus, the list remains locked after your loop finishes, blocking any
thread that tries to access the list later on.  You should be calling
LockList() only once, not repeatedly.

Also, the TIdTCPServer.Contexts list holds TIdContext objects, not
TIdConnection objects.  So you need to fix that as well.

Try this instead:

    var
        List: TList;
    begin
        List := srvProxyTCP.Contexts.LockList;
        try
            for i := 0 to List.Count - 1 do
            try
                ListBox1.Items.Add(TIdContext(List.Items[i]).Connection.Socket.Binding.PeerIP);
            except
            end;
        finally
            srvProxyTCP.Contexts.UnlockList;
        end;
    end;


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive