Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: TClientSocket write progress???

www.cryer.info
Managed Newsgroup Archive

Re: TClientSocket write progress???

Subject:Re: TClientSocket write progress???
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 23 Jan 2008 14:32:58

"Bo Berglund" <bo.berglund@telia.com> wrote in message
news:qj9fp39rsferohbpkb958r9f28a2otejmd@4ax.com...

> But when I send using SendText the complete string I am about to
> send is "swallowed" in an instant and the sendtext call immediately
> returns.

The timing does not matter at all.  You passed a block of data to the
socket.  You know how many bytes you passed in.  The socket returned the
number of bytes it actually accepted.  So you have all the info you need to
update your progress right then and there.

> I only call this once for each block of data I send...
> So there is no progress of blocks being sent to show.

Yes there is.

> the string is about 7 Mb in size

Why are you using strings to hold that much data?  You should be using byte
arrays or streams instead.  In fact, you shouldn't be using SendText() for
that much data anyway, because there is no way the socket can accept 7Mb of
data at one time to begin with.  At the very least, you MUST keep track of
SendText's return value so that you call SendText in a loop until all of the
data has been accepted successfully.  I described that scenerio to you in my
earlier reply, because you have to take the OnWrite event into account.
There is no way around that in this situation.  Your data is too large not
to.  So you may as well redesign how you are managing the data storage so
you can send it more efficiently using SendBuf() and byte offsets.  Deleting
characters from a string and obtaining substrings is going to be a
performance bottleneck during the send of such large data.

> This does not happen, the sendtext method always returns the
> length of the string I am supplying to it...

Not for 7Mb strings, it can't.  The socket's buffer is not that large.  It
is around 8Kb by default.  But even for smaller strings, you still MUST take
the return value and OnWrite events into account properly, or you risk
corrupting your transmissions.  You are NEVER guaranteed that the socket
will accept everything you give it in one go, or receive everything you tell
it to in one go.  That is simply the nature of TCP programming in general.
The sooner you learn that, the more solid and error-proof you will design
your code to be.  I guarantee that you will hit up on this issue eventually.
Every socket programmer does.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive