From Free Pascal wiki

I have some difficulties to use onCanSend property on a TLUDPComponent.
I wanted to use it to send large data streams on the UDP socket.
So I pointed the LUDP.onCanSend on my callback procedure (which will send packet by packet the large data stream) and initialized the transfer by calling the Loopback procedure for each socket.
I was expecting that once the first packet will have been sent, the call back procedure will be fired up again... but nothing.
I was just able to send one packet (relatively small actually: 256 bytes) and that's it!

Could someone tell me what's missing?


You need to "send" in a loop until send fails (returns 0). Only then you know that you can't send so "OnCanSend" will get fired again. This is perhaps a bit confusing, but the meaning of "OnCanSend" is what is called "edge-triggered" in that it will fire ONLY when the status changes from "I can still send" into "I can't send anymore" and then to "I can send again".

So basicly you should add an inner loop which sends until Send returns 0 or all data is sent.

If you need to see in code, look at the lftpclient example, which does this when sending files to the server.

Great, it works just like that!
Sorry for my misunderstanding...
So, if you don't mind, I'll then just add in the article:
OnCanSend - This event is fired whenever new data can be sent again on a socket, after a send function failed, returning 0. It can be used ...

Wiki is a great tool too!