Solved

Socket Question - Help Plz (Borland C++ Builder)

Posted on 2002-05-23
12
645 Views
Last Modified: 2007-12-19
The following doesn't work as enable button:

MainClientSocket->Open ( );

  if ( MainClientSocket->Active )
  {
    MainMenuItem->OnClick = DisconnectMenuItemClick;
    MainMenuItem->Caption = "&Disable";

    MainStatusBar->Panels->Items [0]->Text = "Connected";
  }

how do I wait long enough for the clientsocket component to finish trying, because the active property is still set to false when it checks right away :/
0
Comment
Question by:Aeonin
  • 7
  • 4
12 Comments
 

Author Comment

by:Aeonin
ID: 7030776
A suggestion to do it in another way is great too.

I just need to open that socket, if it fails the event handler etc. of the connect button hould not change, if it succeeds the event handler and the caption need to change to the disconnect handler and caption.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 7031219
If I understand right your problem, you want know, if
connection still active.
Try send message with 0 lenth. If this fails, connection closed (disable), else enable .
0
 

Expert Comment

by:octi
ID: 7031784
Write to the OnError event handler of the MainClientSocket and update the caption there. If the error code is eeConnect, then the connection failed...so you can change the caption.
After handling the error, set the errorcode to no error.
Octi
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:Aeonin
ID: 7032347
No, the code is the event handler for the Connect button, which will make the ClientSocket connect to a specified address.

So, you click connect, it then opens the socket, but if I check the Active property right away it is still set to false, even if the client will connect or has connected, I dont know if it takes time.

Hmm, the onerror may be suitable, let me try.
0
 

Expert Comment

by:octi
ID: 7032382
Please read again my comment...-:)
No need to check the Active property, because the OnError will occure after a connection failure.
So my answer is part of the chapter ..."suggestion to do it in another way" from your question.
0
 

Author Comment

by:Aeonin
ID: 7032558
And no the OnError idea will not work, it must change  the handlers if it connects
0
 

Author Comment

by:Aeonin
ID: 7032568
User> Clicks connect
Program> Opens (tries to anyways) the ClientSocket

Now the program must wait until it connects, or until it fails to connect, howww
0
 

Author Comment

by:Aeonin
ID: 7032575
As you can see, the OnError will only occur if it fails, I cant change the button already to the other status, because someone might click on ít, it will have to wait for the connection
0
 

Accepted Solution

by:
octi earned 50 total points
ID: 7034206
1. Write to the OnConnecting event handler to disable the button. OnConnecting will occure after calling Open, but before the connection is established.
2. Write to the OnConnect event handler to change the caption in case of successful connetion, or
3. Write to the OnError event handler (check if eeConnect error was raised) to enable the connect button back, in case of connection failure.

This event will occure asynchrounisly, you don't have to worry about timing.

Octi
0
 

Author Comment

by:Aeonin
ID: 7034212
Excellent, could you mind giving the same idea for a serversocket, since serversocket does not have an onerror, well, so it seems to me, the onlisten could be used for when a successfull listen, but as far as I know ports may not always be available and the server socket has a posibility of failing while trieing to claim a port.
0
 

Expert Comment

by:octi
ID: 7036452
If the port is busy (a serversocket is already listening on the specified port) the Listen method (of the serversocket) will raise an exception.
So if you want to handle the unsuccessfull Listen, you have to write a try catch block for that.
e.g.

try{
   MainServerSocket->Active = true;
}
catch (...)
{
   ShowMessage("Port is busy");
}
0
 

Author Comment

by:Aeonin
ID: 7037681
Found that out myself already, though borland keeps throwing an error screen even though I catch it, blegh, why didnt borland just add an onerror handler, i can tstand things like this :P

And while you are here.

A TControlBar, a TToolBar and a few autosized buttons on the toolbar,the toolbar is flat and showcaptions.

The point is I want the toolbar to be just as big as the buttons, now I can do that by manually setting the width to that, it displays fine in borland c++ builder, bun when you run it it lets disappear the last button or buttons. Even though the buttons are autosized thus fitting it  checks to display or not diplay them on their non-autosized width.

I also send trhis to borland with a huge list of other errors(still not fixed in bcb6 either too) but never got a response.

Is there anything I forgot?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question