Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-05-23
12
Medium Priority
?
657 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 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