Article View: borland.public.cppbuilder.internet.socket
Article #3074Re: Modify the timeout for open() method
From: enzo
Date: Fri, 02 Dec 2005 09:31
Date: Fri, 02 Dec 2005 09:31
60 lines
3126 bytes
3126 bytes
"enzo" <enzo.arlati@aesys.it> ha scritto nel messaggio
news:438ffe59@newsgroups.borland.com...
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> ha scritto nel messaggio
> news:438f4204$1@newsgroups.borland.com...
> >
> > "enzo" <enzo.arlati@aesys.it> wrote in message
> > news:438ed040@newsgroups.borland.com...
> > Are you using the TClientSocket in blocking or non-blocking mode?
> >
> > In blocking mode, you will have to use a separate worker thread to
> > disconnect the socket if it is not connected after your timeout elapses.
>
> I create and open the socket in blocking mode from inside a thread.
> As the example belowe :
> clientSck = new TClientSocket( NULL );
> clientSck->ClientType = ctBlocking;
> clientSck->Address = ipTarge;
> clientSck->Port = portTarget;
> clientSck->Open();
> if( clientSck->Active == false ) return;
>
> I need to make a fast check before call the open or mybe shorten the
timeout
> if I call open on a pc not ready to listen.
> what do you mean for a separate thread to disconnect the socket, can you
> provide me an example ?
>
> thanks, Enzo
I solved using a solution like this.
Application->ProcessMessages() used inside a thread should not be a good
idea, but for now is working.
I hope someone of your guys have a better idea.
clientSck = new TClientSocket( NULL );
clientSck->ClientType = ctNonBlocking;
clientSck->Address = ipTargetFep;
clientSck->Port = portTargetFep;
clientSck->Open();
for( int idx = 0; idx < 10; idx++ )
{
Application->ProcessMessages();
Sleep( 10 );
if( clientSck->Socket->Connected == true ) break;
}
if( clientSck->Socket->Connected == false )
{
mylog( Format( "[ClientXML] Connessione al server %s FALLITA
", ARRAYOFCONST(( ipTargetFep ))));
return;
}
clientSck->Close();
clientSck->ClientType = ctBlocking;
clientSck->Open();
Technical Details
Message-ID:
<43901442$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<438ed040@newsgroups.borland.com> <438f4204$1@newsgroups.borland.com> <438ffe59@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,234cf6f94ba290e1 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "enzo" <enzo.arlati@aesys.it> From: "enzo" <enzo.arlati@aesys.it> Newsgroups: borland.public.cppbuilder.internet.socket References: <438ed040@newsgroups.borland.com> <438f4204$1@newsgroups.borland.com> <438ffe59@newsgroups.borland.com> Subject: Re: Modify the timeout for open() method Date: Fri, 2 Dec 2005 10:31:29 +0100 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 81.208.124.114 Message-ID: <43901442$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1133515842 81.208.124.114 (2 Dec 2005 01:30:42 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail