Hello Angus,
I have been working with ICS for some time and I had the same problem as
you, I have read the ICS source code and I saw that it doesn´t have this
flow control on send, what they have is the internal buffer where data is
stored and sent in background, so, for example, if you have a 56kbps
connection to send the data and you try to send for example 1mbps of data
using the send routine, the internal buffer will keep growing and growing
and growing, I don´t know if this is correct, but this is what I have
concluded reading the source, because the send routine always put your data
into internal buffer, growing it as data is incoming.
I have an Client / Server application for IP Camera Surveillance
(www.digifort.com.br), and one feature of it works like this, the server
receives images from the IP Cameras and retransmits those images to the
clients connected to this server, but I have have an input from the camera
at any rate (for example 30FPS that will give me an avg of 900KB/s) and the
clients can be connected over the internet, but the client internet
bandwidth will not be able to receive 900KB/s of data, nor the server
internet connection will be able to transmit the images to the client at
this rate, so, if I just receive the images and try to send it without any
verification to the client, my server internal buffer will grow, and grow
and grow because I can´t send this data that I´m receiveing, fast enought.
So, to solve this I have made a server client class derived from
TWSocketClient and implements the following procedure:
function TSocketConexao.GetCanSendWithoutBuffering: Boolean;
begin
FBufHandler.Lock;
try
//If the internal buffer is empty, return TRUE, else, return FALSE
Result := FBufferedByteCount = 0;
finally
FBufHandler.UnLock;
end;
end;
And I have overriden the Send function to be like this:
function TSocketConexao.Send(const Data: TWSocketData; Len: Integer):
Integer;
begin
//Default return
Result := 0;
//Check if we have enouth space on send buffer
if (MaxSendBuffer > 0) and (SendBufferSize >= FMaxSendBuffer) then
exit;
//Send the data using the Send routine from base class
Result := inherited Send(Data, Len);
end;
As you can see, I have also implemented a property called MaxSendBuffer,
with this I can specify how much data I can store into ICS internal buffer,
if I store data on it (It may store more data than MaxSendBuffer permits
into one call, but on the next call if I have data into internal buffer that
is bigger than MaxSendBuffer, then, this routine simply doesn´t send the
data and returns 0 (Data cannot be sent)
So externally, when I call my new send routine it can returns me the len of
buffered data or 0 if data cannot be put into internal buffer, so, if I try
to send and it returns me 0, I have to wait to try to send data again.
On my particular case, I can just discart data that cannot be sent to the
clients, because my data is camera images, and what will happen is that the
client will just receive images at a lower frame rate, because the server is
discarting the images that it cannot send to the client, but in your case I
think that you have to send all the data, so, you should implement some
external checking, to make this flow control.
Ps. My data is also random...
Hope I could help you
Éric Fleming Bonilha
Digifort
----- Original Message -----
From: "Angus Robertson - Magenta Systems Ltd" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, November 19, 2006 8:22 AM
Subject: Re: [twsocket] Flow control
>> Use event OnDataSent to control the flow, and to avoid grow of
>> TWSocket's send buffer.
>
> That is impossible for random data, unless an extra FIFO buffer is used
> externally to TWSocket.
>
> Trying to understand how TIcsBufferHandler works, it appears to be
> multiple 1,460 byte blocks (TIcsBuffer), with new blocks being added if
> data can not be sent sufficiently fast.
>
> So I guess the answer to my question is there is no flow control and the
> buffers will just keep growing if data can not be sent fast enough,
> until the application runs out of memory.
>
> Angus
> --
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://www.elists.org/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
>
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be