Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Assured Minimum Size
| Subject: | Re: Assured Minimum Size |
| Posted by: | "Allan Fernandes" (te..@ssmiths.com) |
| Date: | Thu, 5 Oct 2006 11:21:56 +0530 |
Hi,
I was checking out Sendbuf() with non-blocking sockets. Did not know how to
trigger OnWrite. Checked the Internet and found a crude method, but it
works. coming back to my earlier question, will this method assure me of at
least 1Kb of transfer per receive at the Server's end.
procedure TForm1.ButtonSendDataClick(Sender: TObject);
begin
wTransportBuffer:='abcdefghijklmnop.....' ; // Just some text matter less
than 1kb
// Just trigerring OnWrite
ClientSocket1.Socket.ASyncStyles:=ClientSocket1.Socket.ASyncStyles-[asWrite]
;
ClientSocket1.Socket.ASyncStyles:=ClientSocket1.Socket.ASyncStyles+[asWrite]
;
end;
procedure TForm1.ClientSocket1Write(Sender: TObject; Socket:
TCustomWinSocket);
begin
if wTransportBuffer <>'' then
begin
ClientSocket1.Socket.Sendbuf(wTransportBuffer,length(wTransportBuffer))
;
wTransportBuffer:='' ;
end;
end;
Thanks for being around
Allan
Remy Lebeau (TeamB) <no.spam@no.spam.com> wrote in message
news:4523effc$1@newsgroups.borland.com...
>
> "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