Solved

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

Posted on 2002-05-23
12
643 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

757 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

20 Experts available now in Live!

Get 1:1 Help Now