🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages Started by Paul at NCF Sat, 08 Sep 2007 08:40
Indy 9 to Indy 10 Changes....
#934
Author: Paul at NCF
Date: Sat, 08 Sep 2007 08:40
52 lines
2402 bytes
Just had some time to try rebuilding Indy 10 again, and just want to clarify 
the new event handler parameters for IdUDPServer.  Got most things compiled 
now and just the following to ask.

The IdUDPServer class has the following read event:
    TUDPReadEvent = procedure (Sender: TObject; AData: TIdBytes; ABinding: 
TIdSocketHandle) of object;

So from Indy 9 to 10:
    void __fastcall IdUDPServerUDPRead(TObject *Sender,TStream 
*AData,TIdSocketHandle *ABinding);
to
    void __fastcall IdUDPServerUDPRead(TIdUDPListenerThread* AThread, 
TIdBytes AData, TIdSocketHandle* ABinding);

In my Indy9 read event handler it looks like the following, the read event 
handler reads data from the stream until there is nothing more to read, exit 
loop, then process whats been received.  What I want to know is how this 
changes with Indy 10 and the TIdBytes parameter?  TIdBytes appears to be be 
a byte array wrapper, which doesn't seem the same as a TStream.

Regards,

Paul
----

    try
    {
        int BufSize = AData->Size;
        int BufIndx = 0;
        char * Buf  = RxBuf->Udata;
        bool result = false;

        while (BufSize > 0)
        {
            int iRead = 0;

            iRead = AData->Read( &Buf[BufIndx], BufSize );

            if( iRead > 0 )
            {
                // success
                BufIndx += iRead;
                BufSize -= iRead;
                result = true;
            }
            else
            {
                // fail
                BufSize = 0;
            }
        }
Re: Indy 9 to Indy 10 Changes....
#788
Author: Remy Lebeau (TeamB)
Date: Mon, 10 Sep 2007 18:08
38 lines
2055 bytes
"Paul at NCF" <notplmacca@clara.co.uk> wrote in message
news:46e26004$1@newsgroups.borland.com...

> What I want to know is how this changes with Indy 10 and
> the TIdBytes parameter?

TIdBytes has a Length property.  That will tell you how many bytes are
available.  It also has a '[]' operator, so you can access the individual
bytes just like with any other kind of array.  Which in fact will simplify
your event handler code, because you won't need a temporary buffer anymore.
You can use the TIdBytes as-is:

    void __fastcall IdUDPServerUDPRead(TIdUDPListenerThread* AThread,
TIdBytes AData, TIdSocketHandle* ABinding)
    {
        try
        {
            // assuming Udata is large enoughto hold all of the bytes, of
course...
            memcpy(RxBuf->Udata, &AData[0], AData.Length);
        }
        //...
    }

> TIdBytes appears to be be a byte array wrapper, which
> doesn't seem the same as a TStream.

No, it is not the same.  If you look at the declaration of TIdBytes in
IdGlobal.hpp, you will see that it is a typedef for the VCL's DynamicArray
templated class:

    typedef DynamicArray<Byte> TIdBytes;

DynamicArray is documented in BCB's help files.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads