Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Assured Minimum Size

www.cryer.info
Managed Newsgroup Archive

Re: Assured Minimum Size

Subject:Re: Assured Minimum Size
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Wed, 4 Oct 2006 10:29:35

"Allan Fernandes" <tech@ssmiths.com> wrote in message
news:452366ef@newsgroups.borland.com...

> I am using Delphi 5 with TServerSocket and TClientSocket. I
> use socket.sendtext() to send small text messages successfully.

SendText() is not very reliable.  It is not guaranteed to send the whole
text.  It will return the number of bytes actually sent.  If the size is
less then the string length, you would have to call SendText() again to
re-send the portions that were not sent earlier.  In which case, you should
use SendBuf() directly instead of SendText().

You also have to take into account that if you use the components in
non-blocking mode, if SendText() (or SendBuf()) returns -1 then you have to
wait for the OnWrite event to be triggered on the connection before you can
send any more data to it.  If you have data that is pending during that
time, you will have to cache it, and then send your cache when the event is
triggered.

> When I have to send larger text messages I am not sure that it
> reaches the destination in one packet.

There is no guarantee of that, even with smaller text values.

It is the sender's responsibility to format the data in such a way that the
receiver can detect where one value ends and the next begins, either by
sending each values actual size with the data, or by placing a unique byte
sequence in between each value.  This is important in situations where a
single value is split amongst multiple packets, and when multiple values are
merged into a single packet.  TCP/IP is a byte stream.  There are no
guarantees about the contents of individual packets.  The contents of
logical values that are made up by the packets have to be managed in your
own code.

It is the receiver's responsibility to cache all inbound packets, and to
only process the data values when they are complete.

Go to http://www.deja.com and search through the newsgroup archives.  These
topics have been discussed in more detail many times before.

> Is there any minimum packet size that I can be sure will be received at
> the destination in a single Read event.

No.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive