Article View: borland.public.cppbuilder.internet.socket
Article #4715Re: TClientSocket
From: Vladimir Stefanovic
Date: Wed, 05 Jan 2005 20:51
Date: Wed, 05 Jan 2005 20:51
66 lines
2832 bytes
2832 bytes
> How much time I must wait for when I call
> TClienteSocket->Open() set the Active property
> to true?
You are using ClienteSocket->Open(), not
TClienteSocket->Open(), right?
Well, first you should be aware what client mode you
are using: ctBlocking or ctNonBlocking.
If you are using ctBlocking, the program stops at:
ClienteSocket->Open()
waiting to connect or error, whatever comes first. I haven't
found any good way to set up my timer for ctBlocking mode
to abandon connecting at the time I want.
Anyway, I suggest you to use ctNonBlocking mode.
> In run time I call the Open method of my TClientSocket for
> open the connection, and wait around 3 seconds to be sure
> that the conection was stablished.
That is not a good way 'to be sure' that the connection will 'be'
establiched. Waiting 3 seconds guarntees nothing.
Try something like this
try
{
ClientSocket->Active = false;
ClientSocket->Address = YOUR_ADDRESS;
ClientSocket->Port = YOUR_PORT;
ClientSocket->Active = true;
int ms_start = GetTickCount();
// WAITS FOR 3 SECONDS AS YOU SAID
while ( GetTickCount() - ms_start < 3000 )
{
Forms::Application->ProcessMessages();
if ( ClientSocket->Active )
break;
}
if ( !ClientSocket->Active )
{
// Ensure that socket will be closed event if activation
comes late...
ClientSocket->Active = false;
}
else
{
// do sending with ClientSocket
}
}
catch ( const Exception &e )
{
// handle error
}
Best regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<41dc5342@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41dc4588$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,8d22f1a433b3033e X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Newsgroups: borland.public.cppbuilder.internet.socket References: <41dc4588$1@newsgroups.borland.com> Subject: Re: TClientSocket Date: Wed, 5 Jan 2005 21:51:26 +0100 Lines: 69 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 82.117.212.65 Message-ID: <41dc5342@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1104958274 82.117.212.65 (5 Jan 2005 12:51:14 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail