🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Timeout for TClientServer in ctBlocking ...

#5161
From: Mark Jacobs
Date: Tue, 12 Oct 2004 15:36
72 lines
3568 bytes
The timeout in blocking mode, is set by the parameter to the stream socket
creation function. For example :-

    char bf[999999];
    csstream=new TWinSocketStream(ClientSocket1->Socket,60000);
    if (!csstream->WaitForData(5000)) Memo1->Lines->Append("Nothing to read in 5
seconds");
    else { memset(bf,0,999998); csstream->Read(bf,999998);
Memo1->SetSelTextBuf(bf);}
...
    Memo1->Lines->Append(AnsiString(csstream->Write(bf,strlen(bf)))+" bytes
sent\r\n"); Memo1->Update();
    if (!csstream->WaitForData(10000)) Memo1->Lines->Append("Not ready to read
after 10 seconds\r\n");
    else { memset(bf,0,999998); csstream->Read(bf,999998);
Memo1->SetSelTextBuf(bf);}
...
    delete csstream;

The key line is csstream=new TWinSocketStream(ClientSocket1->Socket,60000);
because it is this 60000 parameter that sets how long it will wait before the
connection times out (60 seconds in this case). The WaitForData call will wait
for 5000 msecs for data to be received by the ClientSocket component when called
as above. If nothing is received in this time, it returns false. Otherwise, you
can use the Read function to read what it's got. The TWinSocketStream object
also has a TimeOut property that can be set at any time to change the timeout on
blocking sockets. None of this works with non-blocking sockets (my favourite :-)

HTH,
-- 
Mark Jacobs

"Vladimir Stefanovic" <spam@not.needed> wrote in message
news:416bede7@newsgroups.borland.com...
| I have TClientSocket in ctBlocking mode.
|
| How can I reduce the time for waiting for the
| connection to be established.
|
| In ctNonBlocking mode I use something like this:
|
|    ClientSocket->Active = true;
|    int ms_start = GetTickCount();
|    while ( GetTickCount() - ms_start < 1000 )
|    {
|       Forms::Application->ProcessMessages();
|       if ( ClientSocket->Active )
|          break; // Speed-up if the connection is establ.
|    }
|
|    if ( !ClientSocket->Active )
|    {
|       // Not connected during one second ...
|       // etc, ...
|
|
| In ctBlocking mode this (of course) does not work
| nor the TTimer (?!). It seems that timer is also 'dead'
| while ...
|
|    ClientSocket->Active = true;
|
| ...is not finished. What can I do? Maybe some real thread...
|
| Also, when I decide to abandon the process of connecting,
| how can I really stop it. Should I use
|
|    ClientSocket->OnError( this,0,0,0 );
|
| or just
|
|    ClientSocket->Active = false;
Technical Details
Message-ID: <416bfa1e@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!sn-xit-04!sn-xit-06!sn-xit-14!supernews.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <416bede7@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,230ad6ee6657e1fc
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?Borland%20Newsgroup>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <416bede7@newsgroups.borland.com>
Subject: Re: Timeout for TClientServer in ctBlocking ...
Date: Tue, 12 Oct 2004 16:36:59 +0100
Lines: 73
Organization: DK Computing
MIME-Version: 1.0
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 81.86.186.94
Message-ID: <416bfa1e@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1097595422 81.86.186.94 (12 Oct 2004 08:37:02 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!sn-xit-04!sn-xit-06!sn-xit-14!supernews.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail