Solved

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

Posted on 2002-05-23
12
644 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now