🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2967

Re: Non-blocking socket - how to detect when server has finished writing to client

#2967
From: Hans Galema
Date: Sat, 31 Dec 2005 15:01
36 lines
2255 bytes
Mark Jacobs wrote:

> void __fastcall TForm1::ClientSocket1Read(TObject *Sender,TCustomWinSocket *Socket)
> {
>   int ii,jj=Socket->ReceiveLength();
>   while (jj>0)
>   {

You do not need a loop here as for sure ReceiveBuf will get
all the bytes indicated by ReceiveLength.

>     ii=Socket->ReceiveBuf(&bf[wh],jj);
>     wh+=ii; bf[wh]='\0'; Sleep(200); jj=Socket->ReceiveLength();
>   }
>   dun=true;
> }

For the rest the use of this loop with a Sleep and then checking
ReceiveLEngth() again is against the idea of the OnRead event.
Just exit the the OnRead handler and wait for the next event. Indeed
then you have to buffer the incoming data. Using a TMemoryStream makes
this simple.

> How do you detect when the server has finished sending data to 
 > the client in a non-blocking environment?

That you have to determine on the server. The server migth
well have send all long time ago. Winsocks buffers incoming
data and TClientSocket gives it in small amounts in the
OnRead event.

If you want to determine on the receiving side if all data belonging
to a message has come in then you need a protocol that
for instance sends the size of the message in an 4 byte integer first.

Hans.
Technical Details
Message-ID: <43b69d6b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!ndsoftware.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43b66ea8@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,e5c1e8b6c618095e
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sat, 31 Dec 2005 16:01:46 +0100
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Non-blocking socket - how to detect when server has finished
 writing to client
References: <43b66ea8@newsgroups.borland.com>
In-Reply-To: <43b66ea8@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 145.98.201.248
Message-ID: <43b69d6b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1136041323 145.98.201.248 (31 Dec 2005 07:02:03 -0700)
Lines: 36
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!ndsoftware.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail