|Subject:||A UDP design question|
|Posted by:||Malcolm Smith (malco…@mjfreelancing.com)|
|Date:||Mon, 17 Sep 2007|
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
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.
C++Builder Developers Journal