Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages
Started by Brian
Wed, 10 May 2006 21:05
Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Brian
Date: Wed, 10 May 2006 21:05
Date: Wed, 10 May 2006 21:05
27 lines
1889 bytes
1889 bytes
In my application, the user clicks a button which brings up a
dialog that allows them to specify an IP address and port. This
address should be the address of a piece of equipment. Anyway, when
the user clicks 'Connect' the application creates a new
TClientSocket (nonBlocking) and attempts to connect to it:
socket=new TClientSocket(Application);
socket->ClientType=ctNonBlocking;
socket->Address=Login->Host->Text;
socket->Port=Login->Port->Text.ToIntDef(2024);
socket->OnError=IPSessionError;
socket->OnRead=IPSessionRead;
socket->OnConnect=IPSessionConnect;
socket->Active=true;
During this process, I bring up a 'please wait' dialog that
contains an Abort button.
If the user presses the Abort button, and the application has not
actually made a connection to anything yet (say it's a bad IP
address), how can I force the attempt to close without having
to wait for the timeout?
I've tried setting the socket to inactive (Active=false), but the
OnIPSessionError event still gets called after the timeout period
expires.
Re: Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Hans Galema
Date: Wed, 10 May 2006 21:41
Date: Wed, 10 May 2006 21:41
19 lines
1604 bytes
1604 bytes
Brian wrote: > During this process, I bring up a 'please wait' dialog that > contains an Abort button. And when do you close that dialog ? > I've tried setting the socket to inactive (Active=false), but the > OnIPSessionError event still gets called after the timeout period > expires. You could let the Abort button set a flag which is checked by the onerroreventhandler. If the flag is set the handler only sets ErrorCode to 0 and returns. No alerts now. That leaves you with the problem to delete the TClientSocket. When are you doing it now ? Hans.
Re: Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Remy Lebeau (TeamB)
Date: Wed, 10 May 2006 21:45
Date: Wed, 10 May 2006 21:45
19 lines
1624 bytes
1624 bytes
"Brian" <brian@nospam.org> wrote in message news:44625587$1@newsgroups.borland.com... > I've tried setting the socket to inactive (Active=false) That will not work for a non-blocking socket. Setting the Active property to false has no effect while the property is still false, and it is not set to true until the connection is fully established. You will have to free the TClientSocket instance instead. > but the OnIPSessionError event still gets called after the > timeout period expires. That is because you did not actually deactivate the TClientSocket, so it continued on with its work until the socket error was reported. Gambit
Re: Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Brian
Date: Wed, 10 May 2006 22:06
Date: Wed, 10 May 2006 22:06
23 lines
1633 bytes
1633 bytes
Hans Galema <notused@notused.nl> wrote: > >And when do you close that dialog ? > I close the dialog when the connection process is complete or the user presses the abort button. > >You could let the Abort button set a flag which is checked by >the onerroreventhandler. If the flag is set the handler only sets >ErrorCode to 0 and returns. No alerts now. > I do have a flag, but I cannot have the event handler check it because the flag could be from another 'login' process, not the aborted process. >That leaves you with the problem to delete the TClientSocket. >When are you doing it now ? The socket gets deleted when the connection is closed (either manually or automatically).
Re: Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Brian
Date: Wed, 10 May 2006 22:08
Date: Wed, 10 May 2006 22:08
10 lines
1386 bytes
1386 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: >That is because you did not actually deactivate the TClientSocket, so it >continued on with its work until the socket error was reported. I do not delete it until I have a final verdict on the connection status - which I do not get until the error message appears. I'll try deleting it when the abort key is pressed, instead of in the event handler for the connection being closed.
Re: Is there a way to allow an 'ABORT' from a TClientSocket connect?
Author: Remy Lebeau (TeamB)
Date: Wed, 10 May 2006 22:34
Date: Wed, 10 May 2006 22:34
15 lines
1486 bytes
1486 bytes
"Brian" <brian@nospam.org> wrote in message news:44626471$1@newsgroups.borland.com... > I do not delete it until I have a final verdict on the connection > status To do what you are asking for, you must delete it when the Abort button is clicked. That is the only way to abort TClientSocket in non-blocking mode. Besides, the user clicking the Abort button sounds like a final verdict to me - the user doesn't care if the connection succeeds or fails, they want it to stop immediately. So you have to delete it to stop it. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads