🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Detecting a client disconnect

#4838
From: Paul Machiaverna
Date: Wed, 24 Nov 2004 18:36
50 lines
3117 bytes
It has been my understanding that OnExecute (IdTCPServer1Execute) is simply a "start" event much like that of a TThread->Execute, where you stay in the method for as long as it takes to get the task completed and then let that method return (thread execution ends).

As for the reading/writing, I'm on to something.  I was calling Readable() to check if there was something to read and then call a read data method.  Of course, readable will return false when the client disconnects and no attempt is made to call read:

if ( AThread->Connection->Socket->Binding->Readable( 1 ) )
{
  // Read it.
  int liCount =
      AThread->Connection->Socket->Binding->Recv(
          lpbyBuffer, 1000, 0 );
}

If Recv() isn't called, the client disconnect isn't detected (no exception thrown).  What I need is another way to read binary data that will return the number of bytes read.  Unfortunately, I have no way of knowing in advance how much the client is going to send other than knowing that it won't be more than 18K bytes.  It could be 4K, 12K, etc.

Paul Mac

"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Paul Machiaverna" <paul.machiaverna@i-stat.com> wrote in message
>news:41a4aed9$3@newsgroups.borland.com...
>
>> In the OnExecute handler method, there is the following code (fragment)
>>
>> while ( true )
>
>Do *not* run your own loop in the OnExecute event.  The OnExecute event
>itself is already looped by TIdTCPServer.  By running your own loop, you are
>preventing TIdTCPServer from performing housekeeping on the socket between
>loop iterations.
>
>>   // If the socket is no longer connected,
>>   if ( !AThread->Connection->Connected() )
>
>There is no need to check that.  TIdTCPServer already does that for you.
>
>>  // Perform reads/writes.
>
>You did not show that code.  I want to make sure that you are not preventing
>TIdTCPServer from managing the socket properly.
>
>> Other info:  INDY 9.0.14, WinXP Pro Version 2002 SP1
>
>9.0.14 is an old version of Indy.  You should upgrade to the current
>development snapshot.
>
>
>Gambit
>
>
Technical Details
Message-ID: <41a4e2b4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41a3a222$1@newsgroups.borland.com> <41a3a429@newsgroups.borland.com> <41a4aed9$3@newsgroups.borland.com> <41a4d9d0$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,2bbc0c2eefeb0788
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Paul Machiaverna" <paul.machiaverna@i-stat.com>
Sender: "Paul Machiaverna" <paul.machiaverna@i-stat.com>
Reply-To: "Paul Machiaverna" <paul.machiaverna@i-stat.com>
Subject: Re: Detecting a client disconnect
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 130.36.11.140     
References: <41a3a222$1@newsgroups.borland.com> <41a3a429@newsgroups.borland.com> <41a4aed9$3@newsgroups.borland.com> <41a4d9d0$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41a4e2b4$1@newsgroups.borland.com>
Date: 24 Nov 2004 11:36:20 -0700
X-Trace: newsgroups.borland.com 1101324980 207.105.83.66 (24 Nov 2004 11:36:20 -0700)
Lines: 51
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail