Re: A UDP design question

Giganews Newsgroups
Subject: Re: A UDP design question
Posted by:  Malcolm Smith (malco…@mjfreelancing.com)
Date: Tue, 18 Sep 2007

After reading the Indy source I think I know a solution to my problem.  Now
that my adaptor class no longer reads/writes using the TIdUDPServer itself
(which would use the FCurrentBinding) I'm wondering if I can do this:

For each OnUDPRead event, add a new binding to the Bindings list (if the
connection is new) and pass around the 'ABinding' parameter to my adaptor -
my class will never live as long as the TIdUDPServer component.  When "I
detect" the connection has gone away, remove the binding.  If this is ok, do
I need to be concerned with locking the bindings list from within the
OnUDPRead event handler.

Reading the code, this looks logical but I want to make sure it is valid.

--
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com

"Malcolm Smith" <malco…@mjfreelancing.com> wrote in message
news:F77E0615CD35E340malco…@mjfreelancing.com...
> Just when I thought I had my UDP code all worked out, I've hit another
> stumbling block related to transmitting data across the internet.
>
> The following scenario works:
>
> * UDP client sends data to a UDP server
> * The UDP server's OnUDPRead event is fired
> * Data is sent back to the client using the Binding parameter of the
> OnUDPRead event
>
> The above is not suitable in my case because the server must push video
> data to the client over a long period of time - hence I have to leave the
> OnUDPRead event so other clients can be serviced.
>
> My code does this:
>
> * In the server's OnUDPRead event I capture the Peer IP/Port information,
> create another thread that contains a TIdUDPClient and use this worker
> thread to send data back to the client, using this approach:
>
> - Using the thread's TIdUDPClient component, I construct a helper object
> called TUDPSocketHandleAdaptor (required for some template code).  In
> simple terms, the object is initialized like so:
>
>  TUDPSocketHandleAdaptor Adaptor( UDPClient->Binding, Timeout, IP, Port )
>
>  (a member called FSocket is assigned as UDPClient->Binding)
>
> - and the data is sent to the client like so:
>
>    FSocket->SendTo( FUDPIP, FUDPPort, pBuffStart, AByteCount );
>
> This has worked perfectly for LAN based scenerios.  Across the web
> however, this cannot communicate.  I guess it is a router based issue....
>
> And based on the fact the first example worked, I can only assume it is
> because I'm not using the original object/binding (whatever it is called)
> used by the TIdUDPServer component.
>
> So, is there a way to get around this or will I have to create my own
> server solution that uses a pool of listeners and transfers the ownership
> of the 'current' listener to each of my worker threads so the
> communication can be continued on the same TIdUCPClient instance.
>
> I hope I've explained this clearly.
>
> --
> Malcolm Smith
> MJ Freelancing
>http://www.mjfreelancing.com
>
> Associate Editor
> C++Builder Developers Journal
>http://www.bcbjournal.com

Replies

In response to

A UDP design question posted by Malcolm Smith on Mon, 17 Sep 2007